package com.ss.android.ugc.aweme.plugin;

import X.0Gp;
import X.6we;
import X.AnonymousClass2X0;
import X.AnonymousClass2XP;
import X.AnonymousClass2Y0;
import X.AnonymousClass2Y1;
import X.AnonymousClass2Y2;
import X.AnonymousClass2YP;
import X.C04702We;
import X.C05012Xj;
import X.C05022Xk;
import X.C05042Xm;
import X.C05132Xv;
import X.C05142Xw;
import X.C05152Xx;
import X.C05162Xy;
import X.Cwu;
import X.JM9;
import X.K09;
import X.K0A;
import X.LWw;
import X.LeS;
import X.PgU;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.keva.Keva;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class RealtimeFeedbackInterceptor implements AnonymousClass2YP {
    public static final AnonymousClass2Y2 LIZLLL = new AnonymousClass2Y2((byte) 0);
    public static final Keva LJFF = Keva.getRepo("realtime_repo");
    public ArrayList<AnonymousClass2Y0> LIZ = new ArrayList<>();
    public C04702We LIZIZ;
    public AnonymousClass2XP LIZJ;
    public final List<C05132Xv> LJ = LeS.LIZJ(new C05132Xv[]{new C05132Xv("video_play_end", new ArrayList()), new C05132Xv("like", new ArrayList()), new C05132Xv("dislike", new ArrayList()), new C05132Xv("like_cancel", new ArrayList())});

    public interface RealtimeApi {
        static {
            Covode.recordClassIndex(97291);
        }

        @JM9(LIZ = "/tiktok/v1/realtime/feedback/")
        PgU<C05012Xj> uploadRealtimeFeedback(@6we C05022Xk r1);
    }

    static {
        Covode.recordClassIndex(97290);
    }

    public final synchronized void LIZ() {
        MethodCollector.i(2444);
        C04702We r0 = this.LIZIZ;
        if (r0 == null || r0.LJ()) {
            C04702We r3 = new C04702We(6000, 5000, new C05042Xm(this));
            this.LIZIZ = r3;
            r3.LIZ();
            C04702We r02 = this.LIZIZ;
            if (r02 != null) {
                r02.LIZIZ();
                MethodCollector.o(2444);
                return;
            }
            MethodCollector.o(2444);
            return;
        }
        C04702We r03 = this.LIZIZ;
        if (r03 != null) {
            r03.LIZLLL();
            MethodCollector.o(2444);
            return;
        }
        MethodCollector.o(2444);
    }

    public final void onEvent(String str) {
        if (str != null) {
            LIZIZ(new C05152Xx(str, (Map<String, String>) null));
        }
    }

    public final synchronized void LIZ(AnonymousClass2Y0 r8) {
        Object obj;
        MethodCollector.i(2392);
        Iterator<AnonymousClass2Y0> it = this.LIZ.iterator();
        while (it.hasNext()) {
            AnonymousClass2Y0 next = it.next();
            Map<String, Object> LIZIZ2 = next.LIZIZ();
            Object obj2 = null;
            if (!(LIZIZ2 == null || (obj = LIZIZ2.get("item_id")) == null)) {
                Map<String, Object> LIZIZ3 = r8.LIZIZ();
                if (LIZIZ3 != null) {
                    obj2 = LIZIZ3.get("item_id");
                }
                if (n.LIZ(obj, obj2) && n.LIZ(next.LIZ(), r8.LIZ())) {
                    MethodCollector.o(2392);
                    return;
                }
            }
        }
        this.LIZ.add(r8);
        LIZ();
        MethodCollector.o(2392);
    }

    private final void LIZIZ(AnonymousClass2Y0 r12) {
        C05152Xx r6;
        Map<String, Object> LIZIZ2 = r12.LIZIZ();
        if (LIZIZ2 != null) {
            Keva keva = LJFF;
            int i = keva.getInt("watched_videos_count", 0);
            if (i > 100) {
                AnonymousClass2X0.LIZJ.LIZIZ();
                AnonymousClass2XP r0 = this.LIZJ;
                if (r0 != null) {
                    r0.onComplete();
                    return;
                }
                return;
            }
            Object obj = LIZIZ2.get("group_id");
            if (!(obj instanceof String)) {
                obj = null;
            }
            Object obj2 = "";
            if (obj == null) {
                obj = obj2;
            }
            Map LIZIZ3 = LWw.LIZIZ(new Cwu[]{new Cwu("item_id", obj)});
            String LIZ2 = r12.LIZ();
            switch (LIZ2.hashCode()) {
                case 3321751:
                    if (LIZ2.equals("like")) {
                        Object obj3 = LIZIZ2.get("duration");
                        if ((obj3 instanceof String) && obj3 != null) {
                            obj2 = obj3;
                        }
                        LIZIZ3.put("play_duration", obj2);
                        r6 = new C05152Xx(r12.LIZ(), LIZIZ3);
                        break;
                    } else {
                        return;
                    }
                case 282427540:
                    if (LIZ2.equals("video_play_end")) {
                        keva.storeInt("watched_videos_count", i + 1);
                        Object obj4 = LIZIZ2.get("play_duration");
                        if (!(obj4 instanceof Long) || obj4 == null) {
                            obj4 = obj2;
                        }
                        Object obj5 = LIZIZ2.get("vduration");
                        if ((obj5 instanceof Float) && obj5 != null) {
                            obj2 = obj5;
                        }
                        LIZIZ3.put("video_duration", obj2.toString());
                        LIZIZ3.put("play_duration", obj4.toString());
                        r6 = new C05152Xx(r12.LIZ(), LIZIZ3);
                        break;
                    } else {
                        return;
                    }
                case 1190532130:
                    if (!LIZ2.equals("like_cancel")) {
                        return;
                    }
                    break;
                case 1671642405:
                    if (!LIZ2.equals("dislike")) {
                        return;
                    }
                    break;
                default:
                    return;
            }
            r6 = new C05152Xx(r12.LIZ(), LIZIZ3);
            for (C05132Xv r3 : this.LJ) {
                if (!(!n.LIZ(r3.LIZ, r6.LIZ))) {
                    K0A k0a = AnonymousClass2Y1.LIZ;
                    List<K09> list = r3.LIZIZ;
                    if (list == null) {
                        n.LIZIZ();
                    }
                    if (k0a.LIZ(list, r6.LIZIZ)) {
                        0Gp.LIZ(new C05142Xw(this, r6));
                    }
                }
            }
        }
    }

    /* JADX WARNING: Can't fix incorrect switch cases order */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final X.C05022Xk LIZ(java.util.ArrayList<X.AnonymousClass2Y0> r11) {
        /*
            r10 = this;
            java.util.ArrayList r3 = new java.util.ArrayList
            r0 = 10
            int r0 = X.9HM.LIZ(r11, r0)
            r3.<init>(r0)
            java.util.Iterator r9 = r11.iterator()
        L_0x000f:
            boolean r0 = r9.hasNext()
            if (r0 == 0) goto L_0x00cd
            java.lang.Object r5 = r9.next()
            X.2Y0 r5 = (X.AnonymousClass2Y0) r5
            X.2Xt r4 = new X.2Xt
            java.util.Map r1 = r5.LIZIZ()
            r2 = 0
            if (r1 == 0) goto L_0x00ca
            java.lang.String r0 = "item_id"
            java.lang.Object r0 = r1.get(r0)
            if (r0 == 0) goto L_0x00ca
            java.lang.String r1 = r0.toString()
        L_0x0030:
            java.lang.String r6 = r5.LIZ()
            int r0 = r6.hashCode()
            switch(r0) {
                case 3321751: goto L_0x008d;
                case 282427540: goto L_0x009c;
                case 1190532130: goto L_0x00ab;
                case 1671642405: goto L_0x00ba;
                default: goto L_0x003b;
            }
        L_0x003b:
            X.2Xu r0 = X.C05122Xu.UNKNOWN
            int r8 = r0.getType()
        L_0x0041:
            java.util.Map r6 = r5.LIZIZ()
            if (r6 == 0) goto L_0x008b
            java.lang.String r0 = "play_duration"
            java.lang.Object r6 = r6.get(r0)
        L_0x004d:
            boolean r0 = r6 instanceof java.lang.String
            if (r0 != 0) goto L_0x0052
            r6 = r2
        L_0x0052:
            java.lang.String r6 = (java.lang.String) r6
            if (r6 == 0) goto L_0x0089
            long r6 = java.lang.Long.parseLong(r6)
            java.lang.Long r7 = java.lang.Long.valueOf(r6)
        L_0x005e:
            java.util.Map r5 = r5.LIZIZ()
            if (r5 == 0) goto L_0x0087
            java.lang.String r0 = "video_duration"
            java.lang.Object r5 = r5.get(r0)
        L_0x006a:
            boolean r0 = r5 instanceof java.lang.String
            if (r0 != 0) goto L_0x006f
            r5 = r2
        L_0x006f:
            java.lang.String r5 = (java.lang.String) r5
            if (r5 == 0) goto L_0x0080
            float r0 = java.lang.Float.parseFloat(r5)
            double r5 = (double) r0
            long r5 = X.LnI.LIZIZ(r5)
            java.lang.Long r2 = java.lang.Long.valueOf(r5)
        L_0x0080:
            r4.<init>(r1, r8, r7, r2)
            r3.add(r4)
            goto L_0x000f
        L_0x0087:
            r5 = r2
            goto L_0x006a
        L_0x0089:
            r7 = r2
            goto L_0x005e
        L_0x008b:
            r6 = r2
            goto L_0x004d
        L_0x008d:
            java.lang.String r0 = "like"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x003b
            X.2Xu r0 = X.C05122Xu.LIKE
            int r8 = r0.getType()
            goto L_0x0041
        L_0x009c:
            java.lang.String r0 = "video_play_end"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x003b
            X.2Xu r0 = X.C05122Xu.VIDEO_PLAY_END
            int r8 = r0.getType()
            goto L_0x0041
        L_0x00ab:
            java.lang.String r0 = "like_cancel"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x003b
            X.2Xu r0 = X.C05122Xu.LIKE_CANCEL
            int r8 = r0.getType()
            goto L_0x0041
        L_0x00ba:
            java.lang.String r0 = "dislike"
            boolean r0 = r6.equals(r0)
            if (r0 == 0) goto L_0x003b
            X.2Xu r0 = X.C05122Xu.DISLIKE
            int r8 = r0.getType()
            goto L_0x0041
        L_0x00ca:
            r1 = r2
            goto L_0x0030
        L_0x00cd:
            java.util.List r3 = (java.util.List) r3
            java.util.ArrayList r4 = new java.util.ArrayList
            r4.<init>()
            java.util.Iterator r3 = r3.iterator()
        L_0x00d8:
            boolean r0 = r3.hasNext()
            if (r0 == 0) goto L_0x00f3
            java.lang.Object r2 = r3.next()
            r0 = r2
            X.2Xt r0 = (X.C05112Xt) r0
            int r1 = r0.LIZIZ
            X.2Xu r0 = X.C05122Xu.UNKNOWN
            int r0 = r0.getType()
            if (r1 == r0) goto L_0x00d8
            r4.add(r2)
            goto L_0x00d8
        L_0x00f3:
            java.util.List r4 = (java.util.List) r4
            X.2Xk r0 = new X.2Xk
            r0.<init>(r4)
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.plugin.RealtimeFeedbackInterceptor.LIZ(java.util.ArrayList):X.2Xk");
    }

    public final void LIZ(String str, Map<String, String> map) {
        if (str != null) {
            LIZIZ(new C05152Xx(str, map));
        }
    }

    public final void LIZ(String str, JSONObject jSONObject) {
        if (str != null) {
            LIZIZ(new C05162Xy(str, jSONObject));
        }
    }
}
