package i3;

import j$.time.Instant;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import m3.AbstractC2467b;
import org.json.JSONArray;
import org.json.JSONObject;
import w4.C3137A;
import x4.AbstractC3256v;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Object f19060b;

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public y(J j4, A4.d dVar) {
        super(2, dVar);
        this.f19063e = j4;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new y(this.f19063e, dVar);
    }

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

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:112:0x0376 A[Catch: all -> 0x01d5, TryCatch #0 {all -> 0x01d5, blocks: (B:48:0x013b, B:93:0x0268, B:52:0x0151, B:55:0x0158, B:57:0x01c7, B:59:0x01cf, B:63:0x01dd, B:65:0x01e3, B:67:0x01eb, B:69:0x01f2, B:71:0x01f8, B:73:0x0200, B:76:0x0209, B:81:0x021c, B:87:0x0231, B:89:0x0246, B:91:0x024d, B:92:0x0259, B:94:0x0281, B:96:0x0294, B:145:0x041f, B:99:0x02cf, B:102:0x02d6, B:104:0x0354, B:106:0x0360, B:110:0x0370, B:112:0x0376, B:114:0x0380, B:118:0x0390, B:120:0x0396, B:122:0x039e, B:126:0x03ad, B:132:0x03c6, B:138:0x03de, B:140:0x03f1, B:142:0x03fc, B:144:0x0410, B:146:0x0444, B:148:0x044d, B:149:0x0456, B:150:0x045f, B:152:0x0465, B:153:0x0471), top: B:162:0x013b }] */
    /* JADX WARN: Removed duplicated region for block: B:116:0x038b  */
    /* JADX WARN: Removed duplicated region for block: B:120:0x0396 A[Catch: all -> 0x01d5, TryCatch #0 {all -> 0x01d5, blocks: (B:48:0x013b, B:93:0x0268, B:52:0x0151, B:55:0x0158, B:57:0x01c7, B:59:0x01cf, B:63:0x01dd, B:65:0x01e3, B:67:0x01eb, B:69:0x01f2, B:71:0x01f8, B:73:0x0200, B:76:0x0209, B:81:0x021c, B:87:0x0231, B:89:0x0246, B:91:0x024d, B:92:0x0259, B:94:0x0281, B:96:0x0294, B:145:0x041f, B:99:0x02cf, B:102:0x02d6, B:104:0x0354, B:106:0x0360, B:110:0x0370, B:112:0x0376, B:114:0x0380, B:118:0x0390, B:120:0x0396, B:122:0x039e, B:126:0x03ad, B:132:0x03c6, B:138:0x03de, B:140:0x03f1, B:142:0x03fc, B:144:0x0410, B:146:0x0444, B:148:0x044d, B:149:0x0456, B:150:0x045f, B:152:0x0465, B:153:0x0471), top: B:162:0x013b }] */
    /* JADX WARN: Removed duplicated region for block: B:124:0x03a9  */
    /* JADX WARN: Removed duplicated region for block: B:128:0x03bc  */
    /* JADX WARN: Removed duplicated region for block: B:131:0x03c3  */
    /* JADX WARN: Removed duplicated region for block: B:134:0x03d4  */
    /* JADX WARN: Removed duplicated region for block: B:137:0x03db  */
    /* JADX WARN: Removed duplicated region for block: B:140:0x03f1 A[Catch: all -> 0x01d5, TryCatch #0 {all -> 0x01d5, blocks: (B:48:0x013b, B:93:0x0268, B:52:0x0151, B:55:0x0158, B:57:0x01c7, B:59:0x01cf, B:63:0x01dd, B:65:0x01e3, B:67:0x01eb, B:69:0x01f2, B:71:0x01f8, B:73:0x0200, B:76:0x0209, B:81:0x021c, B:87:0x0231, B:89:0x0246, B:91:0x024d, B:92:0x0259, B:94:0x0281, B:96:0x0294, B:145:0x041f, B:99:0x02cf, B:102:0x02d6, B:104:0x0354, B:106:0x0360, B:110:0x0370, B:112:0x0376, B:114:0x0380, B:118:0x0390, B:120:0x0396, B:122:0x039e, B:126:0x03ad, B:132:0x03c6, B:138:0x03de, B:140:0x03f1, B:142:0x03fc, B:144:0x0410, B:146:0x0444, B:148:0x044d, B:149:0x0456, B:150:0x045f, B:152:0x0465, B:153:0x0471), top: B:162:0x013b }] */
    /* JADX WARN: Removed duplicated region for block: B:143:0x040c  */
    /* JADX WARN: Removed duplicated region for block: B:148:0x044d A[Catch: all -> 0x01d5, TryCatch #0 {all -> 0x01d5, blocks: (B:48:0x013b, B:93:0x0268, B:52:0x0151, B:55:0x0158, B:57:0x01c7, B:59:0x01cf, B:63:0x01dd, B:65:0x01e3, B:67:0x01eb, B:69:0x01f2, B:71:0x01f8, B:73:0x0200, B:76:0x0209, B:81:0x021c, B:87:0x0231, B:89:0x0246, B:91:0x024d, B:92:0x0259, B:94:0x0281, B:96:0x0294, B:145:0x041f, B:99:0x02cf, B:102:0x02d6, B:104:0x0354, B:106:0x0360, B:110:0x0370, B:112:0x0376, B:114:0x0380, B:118:0x0390, B:120:0x0396, B:122:0x039e, B:126:0x03ad, B:132:0x03c6, B:138:0x03de, B:140:0x03f1, B:142:0x03fc, B:144:0x0410, B:146:0x0444, B:148:0x044d, B:149:0x0456, B:150:0x045f, B:152:0x0465, B:153:0x0471), top: B:162:0x013b }] */
    /* JADX WARN: Removed duplicated region for block: B:152:0x0465 A[Catch: all -> 0x01d5, LOOP:4: B:150:0x045f->B:152:0x0465, LOOP_END, TryCatch #0 {all -> 0x01d5, blocks: (B:48:0x013b, B:93:0x0268, B:52:0x0151, B:55:0x0158, B:57:0x01c7, B:59:0x01cf, B:63:0x01dd, B:65:0x01e3, B:67:0x01eb, B:69:0x01f2, B:71:0x01f8, B:73:0x0200, B:76:0x0209, B:81:0x021c, B:87:0x0231, B:89:0x0246, B:91:0x024d, B:92:0x0259, B:94:0x0281, B:96:0x0294, B:145:0x041f, B:99:0x02cf, B:102:0x02d6, B:104:0x0354, B:106:0x0360, B:110:0x0370, B:112:0x0376, B:114:0x0380, B:118:0x0390, B:120:0x0396, B:122:0x039e, B:126:0x03ad, B:132:0x03c6, B:138:0x03de, B:140:0x03f1, B:142:0x03fc, B:144:0x0410, B:146:0x0444, B:148:0x044d, B:149:0x0456, B:150:0x045f, B:152:0x0465, B:153:0x0471), top: B:162:0x013b }] */
    /* JADX WARN: Removed duplicated region for block: B:170:0x0281 A[EDGE_INSN: B:170:0x0281->B:94:0x0281 BREAK  A[LOOP:0: B:45:0x00d9->B:93:0x0268], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00b8  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x00b9 A[Catch: all -> 0x002a, PHI: r0 r6
      0x00b9: PHI (r0v8 java.lang.Object) = (r0v4 java.lang.Object), (r0v61 java.lang.Object) binds: [B:37:0x00b6, B:16:0x003b] A[DONT_GENERATE, DONT_INLINE]
      0x00b9: PHI (r6v10 java.util.concurrent.atomic.AtomicInteger) = (r6v30 java.util.concurrent.atomic.AtomicInteger), (r6v31 java.util.concurrent.atomic.AtomicInteger) binds: [B:37:0x00b6, B:16:0x003b] A[DONT_GENERATE, DONT_INLINE], TryCatch #2 {all -> 0x002a, blocks: (B:8:0x0023, B:43:0x00cd, B:15:0x0038, B:39:0x00b9, B:36:0x00a7, B:23:0x005d, B:26:0x0075), top: B:166:0x0015 }] */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00cc  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0139  */
    /* JADX WARN: Removed duplicated region for block: B:78:0x0218  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x022c  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x0246 A[Catch: all -> 0x01d5, TryCatch #0 {all -> 0x01d5, blocks: (B:48:0x013b, B:93:0x0268, B:52:0x0151, B:55:0x0158, B:57:0x01c7, B:59:0x01cf, B:63:0x01dd, B:65:0x01e3, B:67:0x01eb, B:69:0x01f2, B:71:0x01f8, B:73:0x0200, B:76:0x0209, B:81:0x021c, B:87:0x0231, B:89:0x0246, B:91:0x024d, B:92:0x0259, B:94:0x0281, B:96:0x0294, B:145:0x041f, B:99:0x02cf, B:102:0x02d6, B:104:0x0354, B:106:0x0360, B:110:0x0370, B:112:0x0376, B:114:0x0380, B:118:0x0390, B:120:0x0396, B:122:0x039e, B:126:0x03ad, B:132:0x03c6, B:138:0x03de, B:140:0x03f1, B:142:0x03fc, B:144:0x0410, B:146:0x0444, B:148:0x044d, B:149:0x0456, B:150:0x045f, B:152:0x0465, B:153:0x0471), top: B:162:0x013b }] */
    /* JADX WARN: Removed duplicated region for block: B:96:0x0294 A[Catch: all -> 0x01d5, TryCatch #0 {all -> 0x01d5, blocks: (B:48:0x013b, B:93:0x0268, B:52:0x0151, B:55:0x0158, B:57:0x01c7, B:59:0x01cf, B:63:0x01dd, B:65:0x01e3, B:67:0x01eb, B:69:0x01f2, B:71:0x01f8, B:73:0x0200, B:76:0x0209, B:81:0x021c, B:87:0x0231, B:89:0x0246, B:91:0x024d, B:92:0x0259, B:94:0x0281, B:96:0x0294, B:145:0x041f, B:99:0x02cf, B:102:0x02d6, B:104:0x0354, B:106:0x0360, B:110:0x0370, B:112:0x0376, B:114:0x0380, B:118:0x0390, B:120:0x0396, B:122:0x039e, B:126:0x03ad, B:132:0x03c6, B:138:0x03de, B:140:0x03f1, B:142:0x03fc, B:144:0x0410, B:146:0x0444, B:148:0x044d, B:149:0x0456, B:150:0x045f, B:152:0x0465, B:153:0x0471), top: B:162:0x013b }] */
    /* JADX WARN: Type inference failed for: r46v1, types: [java.util.concurrent.atomic.AtomicInteger] */
    /* JADX WARN: Type inference failed for: r6v0, types: [int] */
    /* JADX WARN: Type inference failed for: r6v1 */
    /* JADX WARN: Type inference failed for: r6v11 */
    /* JADX WARN: Type inference failed for: r6v12 */
    /* JADX WARN: Type inference failed for: r6v16 */
    /* JADX WARN: Type inference failed for: r6v2, types: [java.util.concurrent.atomic.AtomicInteger] */
    /* JADX WARN: Type inference failed for: r6v20 */
    /* JADX WARN: Type inference failed for: r6v22 */
    /* JADX WARN: Type inference failed for: r6v26 */
    /* JADX WARN: Type inference failed for: r6v27 */
    /* JADX WARN: Type inference failed for: r6v28 */
    /* JADX WARN: Type inference failed for: r6v29 */
    /* JADX WARN: Type inference failed for: r6v6 */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        J j4;
        ?? r6;
        Object objK;
        AtomicInteger atomicInteger;
        Instant instant;
        String str;
        AtomicInteger atomicInteger2;
        Object objF;
        AtomicInteger atomicInteger3;
        Object objF2;
        JSONArray jSONArray;
        JSONArray jSONArray2;
        ArrayList arrayList;
        int length;
        int i6;
        ?? r62;
        ?? r46;
        String str2;
        String str3;
        J j6;
        String str4;
        JSONArray jSONArray3;
        String str5;
        ArrayList arrayList2;
        String str6;
        String str7;
        String str8;
        String str9;
        String str10;
        String str11;
        String str12;
        String str13;
        String str14;
        String str15;
        String str16;
        String str17;
        String str18;
        String str19;
        String str20;
        int length2;
        int i7;
        ArrayList arrayList3;
        JSONArray jSONArray4;
        Iterator it;
        JSONObject jSONObjectOptJSONObject;
        String str21;
        String str22;
        String str23;
        String str24;
        String str25;
        String str26;
        String strOptString;
        String str27;
        String str28;
        String strOptString2;
        String str29;
        String str30;
        String strOptString3;
        String strA;
        String str31;
        String strA2;
        String str32;
        JSONArray jSONArrayOptJSONArray;
        String str33;
        ArrayList arrayList4;
        int i8;
        JSONObject jSONObjectOptJSONObject2;
        JSONArray jSONArray5;
        String str34;
        String strA3;
        String strA4;
        JSONArray jSONArrayOptJSONArray2;
        ArrayList arrayList5;
        JSONArray jSONArrayOptJSONArray3;
        JSONArray jSONArrayOptJSONArray4;
        String str35 = "toString(...)";
        B4.a aVar = B4.a.f492a;
        ?? r63 = this.f19062d;
        J j7 = this.f19063e;
        String str36 = "watchlist_sync_time";
        String str37 = "watchlist_payload";
        try {
        } catch (Throwable th) {
            th = th;
            j4 = j7;
            r6 = r63;
        }
        if (r63 == 0) {
            AbstractC2467b.l(obj);
            AtomicInteger atomicIntegerB = J.b(j7, EnumC2273g.f18934d);
            K k6 = j7.f18889a;
            String string = k6.f18895a.getString("watchlist_payload", null);
            Instant instantW = J.w(j7, k6.f18895a.getString("watchlist_sync_time", null));
            atomicInteger2 = atomicIntegerB;
            atomicInteger2 = atomicIntegerB;
            if (string == null || instantW == null) {
                this.f19059a = atomicInteger2;
                this.f19060b = null;
                this.f19061c = null;
                this.f19062d = 2;
                objF = J.F(j7, "https://api.trakt.tv/sync/watchlist/movies?extended=full,images", 0, this, 6);
                atomicInteger3 = atomicInteger2;
                if (objF == aVar) {
                    JSONArray jSONArray6 = (JSONArray) objF;
                    this.f19059a = atomicInteger3;
                    this.f19060b = jSONArray6;
                    this.f19062d = 3;
                    objF2 = J.F(j7, "https://api.trakt.tv/sync/watchlist/shows?extended=full,images", 0, this, 6);
                    if (objF2 != aVar) {
                    }
                }
            } else {
                this.f19059a = atomicIntegerB;
                this.f19060b = string;
                this.f19061c = instantW;
                this.f19062d = 1;
                objK = j7.K("https://api.trakt.tv/sync/last_activities", this);
                if (objK != aVar) {
                    atomicInteger = atomicIntegerB;
                    instant = instantW;
                    str = string;
                }
            }
            return aVar;
        }
        if (r63 == 1) {
            instant = this.f19061c;
            str = (String) this.f19060b;
            atomicInteger = this.f19059a;
            try {
                AbstractC2467b.l(obj);
                objK = obj;
                atomicInteger = atomicInteger;
            } catch (Throwable th2) {
                th = th2;
                j4 = j7;
                r6 = atomicInteger;
            }
        } else {
            if (r63 == 2) {
                AtomicInteger atomicInteger4 = this.f19059a;
                AbstractC2467b.l(obj);
                objF = obj;
                atomicInteger3 = atomicInteger4;
                JSONArray jSONArray62 = (JSONArray) objF;
                this.f19059a = atomicInteger3;
                this.f19060b = jSONArray62;
                this.f19062d = 3;
                objF2 = J.F(j7, "https://api.trakt.tv/sync/watchlist/shows?extended=full,images", 0, this, 6);
                if (objF2 != aVar) {
                    jSONArray = jSONArray62;
                    r63 = atomicInteger3;
                    jSONArray2 = (JSONArray) objF2;
                    arrayList = new ArrayList();
                    length = jSONArray.length();
                    i6 = 0;
                    r62 = r63;
                    while (true) {
                        r46 = r62;
                        str2 = str37;
                        str3 = str36;
                        j6 = j7;
                        str4 = str35;
                        jSONArray3 = jSONArray2;
                        str5 = "type";
                        arrayList2 = arrayList;
                        str6 = "imdb";
                        str7 = "backdropUrl";
                        str8 = "posterUrl";
                        str9 = "fanart";
                        str10 = "poster";
                        str11 = "tmdb";
                        str12 = "images";
                        str13 = "tmdbId";
                        str14 = "runTime";
                        str15 = "ids";
                        str16 = "runtime";
                        str17 = "listed_at";
                        str18 = "certificate";
                        str19 = "popularity";
                        str20 = "";
                        if (i6 < length) {
                        }
                        th = th;
                        r6 = r46;
                        j4 = j6;
                        J.h(j4, EnumC2273g.f18934d, r6);
                        throw th;
                        i6++;
                        r62 = r46;
                        arrayList = arrayList5;
                        str37 = str2;
                        str36 = str3;
                        j7 = j6;
                        str35 = str4;
                        jSONArray2 = jSONArray3;
                        length = i8;
                        jSONArray = jSONArray5;
                    }
                    String str38 = "genres";
                    String str39 = "logo";
                    String str40 = "rating";
                    String str41 = "year";
                    length2 = jSONArray3.length();
                    String str42 = "votes";
                    i7 = 0;
                    while (i7 < length2) {
                    }
                    arrayList3 = arrayList2;
                    if (arrayList3.size() > 1) {
                    }
                    jSONArray4 = new JSONArray();
                    it = arrayList3.iterator();
                    while (it.hasNext()) {
                    }
                    String string2 = Instant.now().toString();
                    kotlin.jvm.internal.o.g(string2, str4);
                    j4 = j6;
                    K k7 = j4.f18889a;
                    String string3 = jSONArray4.toString();
                    kotlin.jvm.internal.o.g(string3, str4);
                    k7.getClass();
                    k7.f18895a.edit().putString(str3, string2).putString(str2, string3).apply();
                    J.h(j4, EnumC2273g.f18934d, r46);
                    return jSONArray4;
                }
                return aVar;
            }
            if (r63 != 3) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            jSONArray = (JSONArray) this.f19060b;
            AtomicInteger atomicInteger5 = this.f19059a;
            AbstractC2467b.l(obj);
            objF2 = obj;
            r63 = atomicInteger5;
            jSONArray2 = (JSONArray) objF2;
            arrayList = new ArrayList();
            length = jSONArray.length();
            i6 = 0;
            r62 = r63;
            while (true) {
                r46 = r62;
                str2 = str37;
                str3 = str36;
                j6 = j7;
                str4 = str35;
                jSONArray3 = jSONArray2;
                str5 = "type";
                arrayList2 = arrayList;
                str6 = "imdb";
                str7 = "backdropUrl";
                str8 = "posterUrl";
                str9 = "fanart";
                str10 = "poster";
                str11 = "tmdb";
                str12 = "images";
                str13 = "tmdbId";
                str14 = "runTime";
                str15 = "ids";
                str16 = "runtime";
                str17 = "listed_at";
                str18 = "certificate";
                str19 = "popularity";
                str20 = "";
                if (i6 < length) {
                    break;
                }
                i8 = length;
                try {
                    JSONObject jSONObject = jSONArray.getJSONObject(i6);
                    String strOptString4 = jSONObject.optString("listed_at", "");
                    JSONObject jSONObjectOptJSONObject3 = jSONObject.optJSONObject("movie");
                    if (jSONObjectOptJSONObject3 == null || (jSONObjectOptJSONObject2 = jSONObjectOptJSONObject3.optJSONObject("ids")) == null) {
                        jSONArray5 = jSONArray;
                        arrayList5 = arrayList2;
                    } else {
                        jSONArray5 = jSONArray;
                        JSONObject jSONObject2 = new JSONObject();
                        jSONObject2.put("tmdbId", jSONObjectOptJSONObject2.optInt("tmdb"));
                        jSONObject2.put("traktId", jSONObjectOptJSONObject2.optInt("trakt"));
                        jSONObject2.put("imdbId", jSONObjectOptJSONObject2.optString("imdb"));
                        jSONObject2.put("type", "movie");
                        jSONObject2.put("title", jSONObjectOptJSONObject3.optString("title"));
                        jSONObject2.put("overview", jSONObjectOptJSONObject3.optString("overview"));
                        jSONObject2.put("year", String.valueOf(jSONObjectOptJSONObject3.optInt("year")));
                        jSONObject2.put("rating", jSONObjectOptJSONObject3.optDouble("rating"));
                        jSONObject2.put(str19, jSONObjectOptJSONObject3.optDouble("votes"));
                        AtomicLong atomicLong = J.f18885e;
                        j6.getClass();
                        jSONObject2.put(str18, J.L(jSONObjectOptJSONObject3));
                        jSONObject2.put(str14, jSONObjectOptJSONObject3.optInt(str16));
                        JSONObject jSONObjectOptJSONObject4 = jSONObjectOptJSONObject3.optJSONObject(str12);
                        String strZ = J.z((jSONObjectOptJSONObject4 == null || (jSONArrayOptJSONArray4 = jSONObjectOptJSONObject4.optJSONArray(str10)) == null) ? null : jSONArrayOptJSONArray4.optString(0));
                        String strZ2 = J.z((jSONObjectOptJSONObject4 == null || (jSONArrayOptJSONArray3 = jSONObjectOptJSONObject4.optJSONArray(str9)) == null) ? null : jSONArrayOptJSONArray3.optString(0));
                        if (jSONObjectOptJSONObject4 != null) {
                            str34 = "logo";
                            JSONArray jSONArrayOptJSONArray5 = jSONObjectOptJSONObject4.optJSONArray(str34);
                            String strOptString5 = jSONArrayOptJSONArray5 != null ? jSONArrayOptJSONArray5.optString(0) : null;
                            String strZ3 = J.z(strOptString5);
                            strA3 = g3.u.a(strZ, false);
                            if (S4.p.Q0(strA3)) {
                                if (strZ == null) {
                                    strZ = "";
                                }
                                strA3 = strZ;
                            }
                            jSONObject2.put(str8, strA3);
                            strA4 = g3.u.a(strZ2, true);
                            if (S4.p.Q0(strA4)) {
                                if (strZ2 != null) {
                                    str20 = strZ2;
                                }
                                strA4 = str20;
                            }
                            jSONObject2.put(str7, strA4);
                            jSONObject2.put(str34, strZ3);
                            jSONArrayOptJSONArray2 = jSONObjectOptJSONObject3.optJSONArray("genres");
                            JSONArray jSONArray7 = new JSONArray();
                            if (jSONArrayOptJSONArray2 != null) {
                                int length3 = jSONArrayOptJSONArray2.length();
                                for (int i9 = 0; i9 < length3; i9++) {
                                    jSONArray7.put(jSONArrayOptJSONArray2.getString(i9));
                                }
                            }
                            jSONObject2.put("genres", jSONArray7);
                            w4.k kVar = new w4.k(strOptString4, jSONObject2);
                            arrayList5 = arrayList2;
                            arrayList5.add(kVar);
                        } else {
                            str34 = "logo";
                        }
                        String strZ32 = J.z(strOptString5);
                        strA3 = g3.u.a(strZ, false);
                        if (S4.p.Q0(strA3)) {
                        }
                        jSONObject2.put(str8, strA3);
                        strA4 = g3.u.a(strZ2, true);
                        if (S4.p.Q0(strA4)) {
                        }
                        jSONObject2.put(str7, strA4);
                        jSONObject2.put(str34, strZ32);
                        jSONArrayOptJSONArray2 = jSONObjectOptJSONObject3.optJSONArray("genres");
                        JSONArray jSONArray72 = new JSONArray();
                        if (jSONArrayOptJSONArray2 != null) {
                        }
                        jSONObject2.put("genres", jSONArray72);
                        w4.k kVar2 = new w4.k(strOptString4, jSONObject2);
                        arrayList5 = arrayList2;
                        arrayList5.add(kVar2);
                    }
                    i6++;
                    r62 = r46;
                    arrayList = arrayList5;
                    str37 = str2;
                    str36 = str3;
                    j7 = j6;
                    str35 = str4;
                    jSONArray2 = jSONArray3;
                    length = i8;
                    jSONArray = jSONArray5;
                } catch (Throwable th3) {
                    th = th3;
                    r6 = r46;
                    j4 = j6;
                }
                th = th3;
                r6 = r46;
                j4 = j6;
                J.h(j4, EnumC2273g.f18934d, r6);
                throw th;
            }
            String str382 = "genres";
            String str392 = "logo";
            String str402 = "rating";
            String str412 = "year";
            length2 = jSONArray3.length();
            String str422 = "votes";
            i7 = 0;
            while (i7 < length2) {
                String str43 = str402;
                int i10 = length2;
                JSONArray jSONArray8 = jSONArray3;
                JSONObject jSONObject3 = jSONArray8.getJSONObject(i7);
                int i11 = i7;
                String strOptString6 = jSONObject3.optString(str17, str20);
                String str44 = str20;
                JSONObject jSONObjectOptJSONObject5 = jSONObject3.optJSONObject("show");
                if (jSONObjectOptJSONObject5 == null || (jSONObjectOptJSONObject = jSONObjectOptJSONObject5.optJSONObject(str15)) == null) {
                    String str45 = str392;
                    str30 = str11;
                    str31 = str8;
                    str33 = str45;
                    str21 = str17;
                    str22 = str15;
                    str27 = str9;
                    str26 = str422;
                    str402 = str43;
                    str24 = str6;
                    str23 = str13;
                    str25 = str5;
                    str28 = str412;
                    arrayList4 = arrayList2;
                    str32 = str382;
                } else {
                    str21 = str17;
                    JSONObject jSONObject4 = new JSONObject();
                    str22 = str15;
                    jSONObject4.put(str13, jSONObjectOptJSONObject.optInt(str11));
                    jSONObject4.put("traktId", jSONObjectOptJSONObject.optInt("trakt"));
                    jSONObject4.put("imdbId", jSONObjectOptJSONObject.optString(str6));
                    jSONObject4.put(str5, "tv");
                    jSONObject4.put("title", jSONObjectOptJSONObject5.optString("title"));
                    jSONObject4.put("overview", jSONObjectOptJSONObject5.optString("overview"));
                    jSONObject4.put(str412, String.valueOf(jSONObjectOptJSONObject5.optInt(str412)));
                    str23 = str13;
                    str402 = str43;
                    str24 = str6;
                    jSONObject4.put(str402, jSONObjectOptJSONObject5.optDouble(str402));
                    String str46 = str422;
                    str25 = str5;
                    double dOptDouble = jSONObjectOptJSONObject5.optDouble(str46);
                    str26 = str46;
                    String str47 = str19;
                    jSONObject4.put(str47, dOptDouble);
                    AtomicLong atomicLong2 = J.f18885e;
                    j6.getClass();
                    String str48 = str18;
                    jSONObject4.put(str48, J.L(jSONObjectOptJSONObject5));
                    str19 = str47;
                    String str49 = str16;
                    int iOptInt = jSONObjectOptJSONObject5.optInt(str49);
                    str16 = str49;
                    String str50 = str14;
                    jSONObject4.put(str50, iOptInt);
                    str14 = str50;
                    String str51 = str12;
                    JSONObject jSONObjectOptJSONObject6 = jSONObjectOptJSONObject5.optJSONObject(str51);
                    if (jSONObjectOptJSONObject6 != null) {
                        str12 = str51;
                        str18 = str48;
                        String str52 = str10;
                        JSONArray jSONArrayOptJSONArray6 = jSONObjectOptJSONObject6.optJSONArray(str52);
                        if (jSONArrayOptJSONArray6 != null) {
                            str10 = str52;
                            strOptString = jSONArrayOptJSONArray6.optString(0);
                            String strZ4 = J.z(strOptString);
                            if (jSONObjectOptJSONObject6 == null) {
                                String str53 = str9;
                                str28 = str412;
                                JSONArray jSONArrayOptJSONArray7 = jSONObjectOptJSONObject6.optJSONArray(str53);
                                if (jSONArrayOptJSONArray7 != null) {
                                    str27 = str53;
                                    strOptString2 = jSONArrayOptJSONArray7.optString(0);
                                    String strZ5 = J.z(strOptString2);
                                    if (jSONObjectOptJSONObject6 != null) {
                                        str29 = str392;
                                        JSONArray jSONArrayOptJSONArray8 = jSONObjectOptJSONObject6.optJSONArray(str29);
                                        if (jSONArrayOptJSONArray8 != null) {
                                            str30 = str11;
                                            strOptString3 = jSONArrayOptJSONArray8.optString(0);
                                        }
                                        String strZ6 = J.z(strOptString3);
                                        strA = g3.u.a(strZ4, false);
                                        if (S4.p.Q0(strA)) {
                                            strZ4 = strA;
                                        } else if (strZ4 == null) {
                                            strZ4 = str44;
                                        }
                                        str31 = str8;
                                        jSONObject4.put(str31, strZ4);
                                        strA2 = g3.u.a(strZ5, true);
                                        if (S4.p.Q0(strA2)) {
                                            strZ5 = strA2;
                                        } else if (strZ5 == null) {
                                            strZ5 = str44;
                                        }
                                        String str54 = str7;
                                        jSONObject4.put(str54, strZ5);
                                        jSONObject4.put(str29, strZ6);
                                        str32 = str382;
                                        jSONArrayOptJSONArray = jSONObjectOptJSONObject5.optJSONArray(str32);
                                        JSONArray jSONArray9 = new JSONArray();
                                        if (jSONArrayOptJSONArray == null) {
                                            str7 = str54;
                                            str33 = str29;
                                            int i12 = 0;
                                            for (int length4 = jSONArrayOptJSONArray.length(); i12 < length4; length4 = length4) {
                                                jSONArray9.put(jSONArrayOptJSONArray.getString(i12));
                                                i12++;
                                            }
                                        } else {
                                            str7 = str54;
                                            str33 = str29;
                                        }
                                        jSONObject4.put(str32, jSONArray9);
                                        arrayList4 = arrayList2;
                                        arrayList4.add(new w4.k(strOptString6, jSONObject4));
                                    } else {
                                        str29 = str392;
                                    }
                                    str30 = str11;
                                    strOptString3 = null;
                                    String strZ62 = J.z(strOptString3);
                                    strA = g3.u.a(strZ4, false);
                                    if (S4.p.Q0(strA)) {
                                    }
                                    str31 = str8;
                                    jSONObject4.put(str31, strZ4);
                                    strA2 = g3.u.a(strZ5, true);
                                    if (S4.p.Q0(strA2)) {
                                    }
                                    String str542 = str7;
                                    jSONObject4.put(str542, strZ5);
                                    jSONObject4.put(str29, strZ62);
                                    str32 = str382;
                                    jSONArrayOptJSONArray = jSONObjectOptJSONObject5.optJSONArray(str32);
                                    JSONArray jSONArray92 = new JSONArray();
                                    if (jSONArrayOptJSONArray == null) {
                                    }
                                    jSONObject4.put(str32, jSONArray92);
                                    arrayList4 = arrayList2;
                                    arrayList4.add(new w4.k(strOptString6, jSONObject4));
                                } else {
                                    str27 = str53;
                                }
                            } else {
                                str27 = str9;
                                str28 = str412;
                            }
                            strOptString2 = null;
                            String strZ52 = J.z(strOptString2);
                            if (jSONObjectOptJSONObject6 != null) {
                            }
                            str30 = str11;
                            strOptString3 = null;
                            String strZ622 = J.z(strOptString3);
                            strA = g3.u.a(strZ4, false);
                            if (S4.p.Q0(strA)) {
                            }
                            str31 = str8;
                            jSONObject4.put(str31, strZ4);
                            strA2 = g3.u.a(strZ52, true);
                            if (S4.p.Q0(strA2)) {
                            }
                            String str5422 = str7;
                            jSONObject4.put(str5422, strZ52);
                            jSONObject4.put(str29, strZ622);
                            str32 = str382;
                            jSONArrayOptJSONArray = jSONObjectOptJSONObject5.optJSONArray(str32);
                            JSONArray jSONArray922 = new JSONArray();
                            if (jSONArrayOptJSONArray == null) {
                            }
                            jSONObject4.put(str32, jSONArray922);
                            arrayList4 = arrayList2;
                            arrayList4.add(new w4.k(strOptString6, jSONObject4));
                        } else {
                            str10 = str52;
                        }
                    } else {
                        str12 = str51;
                        str18 = str48;
                    }
                    strOptString = null;
                    String strZ42 = J.z(strOptString);
                    if (jSONObjectOptJSONObject6 == null) {
                    }
                    strOptString2 = null;
                    String strZ522 = J.z(strOptString2);
                    if (jSONObjectOptJSONObject6 != null) {
                    }
                    str30 = str11;
                    strOptString3 = null;
                    String strZ6222 = J.z(strOptString3);
                    strA = g3.u.a(strZ42, false);
                    if (S4.p.Q0(strA)) {
                    }
                    str31 = str8;
                    jSONObject4.put(str31, strZ42);
                    strA2 = g3.u.a(strZ522, true);
                    if (S4.p.Q0(strA2)) {
                    }
                    String str54222 = str7;
                    jSONObject4.put(str54222, strZ522);
                    jSONObject4.put(str29, strZ6222);
                    str32 = str382;
                    jSONArrayOptJSONArray = jSONObjectOptJSONObject5.optJSONArray(str32);
                    JSONArray jSONArray9222 = new JSONArray();
                    if (jSONArrayOptJSONArray == null) {
                    }
                    jSONObject4.put(str32, jSONArray9222);
                    arrayList4 = arrayList2;
                    arrayList4.add(new w4.k(strOptString6, jSONObject4));
                }
                i7 = i11 + 1;
                String str55 = str33;
                str8 = str31;
                str11 = str30;
                str392 = str55;
                str382 = str32;
                arrayList2 = arrayList4;
                str13 = str23;
                jSONArray3 = jSONArray8;
                str412 = str28;
                length2 = i10;
                str20 = str44;
                str5 = str25;
                str6 = str24;
                str17 = str21;
                str15 = str22;
                str422 = str26;
                str9 = str27;
            }
            arrayList3 = arrayList2;
            if (arrayList3.size() > 1) {
                AbstractC3256v.J(arrayList3, new Q2.i(6));
            }
            jSONArray4 = new JSONArray();
            it = arrayList3.iterator();
            while (it.hasNext()) {
                jSONArray4.put(((w4.k) it.next()).f25470b);
            }
            String string22 = Instant.now().toString();
            kotlin.jvm.internal.o.g(string22, str4);
            j4 = j6;
            try {
                K k72 = j4.f18889a;
                String string32 = jSONArray4.toString();
                kotlin.jvm.internal.o.g(string32, str4);
                k72.getClass();
                k72.f18895a.edit().putString(str3, string22).putString(str2, string32).apply();
                J.h(j4, EnumC2273g.f18934d, r46);
                return jSONArray4;
            } catch (Throwable th4) {
                th = th4;
                r6 = r46;
            }
        }
        if (!J.a(j7, (JSONObject) objK, instant, "watchlist", new String[]{"updated_at"})) {
            JSONArray jSONArrayS = J.s(j7, str);
            J.h(j7, EnumC2273g.f18934d, atomicInteger);
            return jSONArrayS;
        }
        atomicInteger2 = atomicInteger;
        this.f19059a = atomicInteger2;
        this.f19060b = null;
        this.f19061c = null;
        this.f19062d = 2;
        objF = J.F(j7, "https://api.trakt.tv/sync/watchlist/movies?extended=full,images", 0, this, 6);
        atomicInteger3 = atomicInteger2;
        if (objF == aVar) {
        }
        return aVar;
    }
}
