package i3;

import c0.C1217r;
import h3.C2167o4;
import java.io.Closeable;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import m3.AbstractC2467b;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONObject;
import w4.C3137A;
import x4.AbstractC3257w;

/* JADX INFO: loaded from: classes.dex */
public final class I extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public AtomicInteger f18874a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public kotlin.jvm.internal.y f18875b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f18876c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ int f18877d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ int f18878e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ boolean f18879f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ boolean f18880j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ Integer f18881k;
    public final /* synthetic */ Integer l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final /* synthetic */ Integer f18882m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final /* synthetic */ Long f18883n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final /* synthetic */ J f18884o;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public I(int i6, int i7, boolean z6, boolean z7, Integer num, Integer num2, Integer num3, Long l, J j4, A4.d dVar) {
        super(2, dVar);
        this.f18877d = i6;
        this.f18878e = i7;
        this.f18879f = z6;
        this.f18880j = z7;
        this.f18881k = num;
        this.l = num2;
        this.f18882m = num3;
        this.f18883n = l;
        this.f18884o = j4;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new I(this.f18877d, this.f18878e, this.f18879f, this.f18880j, this.f18881k, this.l, this.f18882m, this.f18883n, this.f18884o, dVar);
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((I) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x0067  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x006a  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x007a  */
    /* JADX WARN: Removed duplicated region for block: B:41:0x007d  */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        boolean z6;
        String string;
        AtomicInteger atomicIntegerB;
        Object objB;
        kotlin.jvm.internal.y yVar;
        int iIntValue;
        int iIntValue2;
        AtomicInteger atomicInteger;
        Throwable th;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f18876c;
        J j4 = this.f18884o;
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            int i7 = this.f18877d;
            if (i7 <= 0) {
                return Boolean.FALSE;
            }
            int iIntValue3 = 0;
            int iV = L4.a.v(this.f18878e, 0, 100);
            boolean z7 = this.f18879f;
            String str = z7 ? "stop" : "pause";
            boolean z8 = this.f18880j;
            Integer num = this.f18882m;
            Integer num2 = this.l;
            Integer num3 = this.f18881k;
            if (!z7) {
                z6 = z7;
                string = null;
            } else if (z8) {
                string = Z0.o.l("movie:", i7);
                z6 = z7;
            } else if (num3 == null) {
                iIntValue = 0;
                if (num2 == null) {
                    iIntValue2 = 0;
                    if (num != null) {
                        Integer num4 = num.intValue() > 0 ? num : null;
                        if (num4 != null) {
                            iIntValue3 = num4.intValue();
                        }
                    }
                    z6 = z7;
                    StringBuilder sbQ = com.google.android.recaptcha.internal.a.q(i7, iIntValue, "tv:", ":s", ":e");
                    sbQ.append(iIntValue2);
                    sbQ.append(":epTmdb");
                    sbQ.append(iIntValue3);
                    string = sbQ.toString();
                } else {
                    Integer num5 = num2.intValue() > 0 ? num2 : null;
                    if (num5 != null) {
                        iIntValue2 = num5.intValue();
                    }
                    if (num != null) {
                    }
                    z6 = z7;
                    StringBuilder sbQ2 = com.google.android.recaptcha.internal.a.q(i7, iIntValue, "tv:", ":s", ":e");
                    sbQ2.append(iIntValue2);
                    sbQ2.append(":epTmdb");
                    sbQ2.append(iIntValue3);
                    string = sbQ2.toString();
                }
            } else {
                Integer num6 = num3.intValue() > 0 ? num3 : null;
                if (num6 != null) {
                    iIntValue = num6.intValue();
                }
                if (num2 == null) {
                }
            }
            Long l = this.f18883n;
            if (l == null || l.longValue() <= 0) {
                l = null;
            }
            if (z6 && l != null && string != null) {
                ConcurrentHashMap concurrentHashMap = J.f18887g;
                Set setKeySet = concurrentHashMap.keySet();
                kotlin.jvm.internal.o.g(setKeySet, "<get-keys>(...)");
                AbstractC3257w.Q(setKeySet, new androidx.compose.runtime.snapshots.e(l, 6));
                new C2167o4(11);
                Object objComputeIfAbsent = concurrentHashMap.computeIfAbsent(l, new H());
                kotlin.jvm.internal.o.g(objComputeIfAbsent, "computeIfAbsent(...)");
                if (!((Set) objComputeIfAbsent).add(string)) {
                    return Boolean.TRUE;
                }
            }
            JSONObject jSONObject = new JSONObject();
            if (z8) {
                jSONObject.put("movie", new JSONObject().put("ids", new JSONObject().put("tmdb", i7)));
            } else if (num != null && num.intValue() > 0) {
                jSONObject.put("episode", new JSONObject().put("ids", new JSONObject().put("tmdb", num.intValue())));
            } else {
                if (num3 == null || num2 == null) {
                    return Boolean.FALSE;
                }
                jSONObject.put("show", new JSONObject().put("ids", new JSONObject().put("tmdb", i7)));
                jSONObject.put("episode", new JSONObject().put("season", num3.intValue()).put("number", num2.intValue()));
            }
            jSONObject.put("progress", iV);
            String strConcat = "https://api.trakt.tv/scrobble/".concat(str);
            kotlin.jvm.internal.o.g(jSONObject.toString(), "toString(...)");
            atomicIntegerB = J.b(j4, EnumC2273g.f18935e);
            try {
                kotlin.jvm.internal.y yVar2 = new kotlin.jvm.internal.y();
                C1217r c1217r = new C1217r(strConcat, j4, jSONObject);
                this.f18874a = atomicIntegerB;
                this.f18875b = yVar2;
                this.f18876c = 1;
                objB = j4.B(c1217r, true, true, this);
                if (objB == aVar) {
                    return aVar;
                }
                yVar = yVar2;
            } catch (Throwable th2) {
                th = th2;
                atomicInteger = atomicIntegerB;
                J.h(j4, EnumC2273g.f18935e, atomicInteger);
                throw th;
            }
        } else {
            if (i6 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            yVar = this.f18875b;
            atomicInteger = this.f18874a;
            try {
                AbstractC2467b.l(obj);
                atomicIntegerB = atomicInteger;
                objB = obj;
            } catch (Throwable th3) {
                th = th3;
                J.h(j4, EnumC2273g.f18935e, atomicInteger);
                throw th;
            }
        }
        Closeable closeable = (Closeable) objB;
        try {
            Response response = (Response) closeable;
            boolean zC = response.c();
            yVar.f20130a = zC;
            if (!zC) {
                try {
                    ResponseBody responseBody = response.f22146j;
                    if (responseBody != null) {
                        S4.p.m1(500, responseBody.d());
                    }
                } catch (Exception unused) {
                }
            }
            android.support.v4.media.session.b.j(closeable, null);
            Boolean boolValueOf = Boolean.valueOf(yVar.f20130a);
            J.h(j4, EnumC2273g.f18935e, atomicIntegerB);
            return boolValueOf;
        } finally {
        }
    }
}
