package R2;

import C4.j;
import M2.C0556x0;
import N2.r;
import S4.w;
import e4.C;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import q.AbstractC2761L;
import w4.C3137A;
import w4.k;
import x4.AbstractC3229F;
import x4.AbstractC3251q;
import x4.AbstractC3252r;
import x4.y;
import x4.z;

/* JADX INFO: loaded from: classes.dex */
public final class b extends j implements J4.f {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public /* synthetic */ List f6049c;

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ b(String str, r rVar, A4.d dVar, int i6) {
        super(3, dVar);
        this.f6047a = i6;
        this.f6050d = str;
        this.f6051e = rVar;
    }

    @Override // J4.f
    public final Object invoke(Object obj, Object obj2, Object obj3) {
        int i6 = this.f6047a;
        List list = (List) obj;
        ((Number) obj2).intValue();
        A4.d dVar = (A4.d) obj3;
        switch (i6) {
            case 0:
                b bVar = new b(this.f6050d, this.f6051e, dVar, 0);
                bVar.f6049c = list;
                return bVar.invokeSuspend(C3137A.f25453a);
            default:
                b bVar2 = new b(this.f6050d, this.f6051e, dVar, 1);
                bVar2.f6049c = list;
                return bVar2.invokeSuspend(C3137A.f25453a);
        }
    }

    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        Object objY;
        List list;
        Long lC0;
        String string;
        Object objH0;
        switch (this.f6047a) {
            case 0:
                B4.a aVar = B4.a.f492a;
                int i6 = this.f6048b;
                if (i6 == 0) {
                    AbstractC2467b.l(obj);
                    List list2 = this.f6049c;
                    String strG = AbstractC2761L.g("https://www.premiumize.me/api/cache/check?", AbstractC3251q.m0(list2, "&", null, null, new C0556x0(26), 30), "&apikey=", URLEncoder.encode(this.f6050d, "UTF-8"));
                    z zVar = z.f26066a;
                    this.f6049c = list2;
                    this.f6048b = 1;
                    objY = C.Y(strG, zVar, this.f6051e, this);
                    if (objY == aVar) {
                        return aVar;
                    }
                    list = list2;
                } else {
                    if (i6 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    list = this.f6049c;
                    AbstractC2467b.l(obj);
                    objY = obj;
                }
                Map map = (Map) objY;
                List list3 = y.f26065a;
                if (map == null || !o.c(map.get("status"), "success")) {
                    return list3;
                }
                Object obj2 = map.get("response");
                List list4 = obj2 instanceof List ? (List) obj2 : null;
                if (list4 == null) {
                    list4 = list3;
                }
                Object obj3 = map.get("filename");
                List list5 = obj3 instanceof List ? (List) obj3 : null;
                if (list5 == null) {
                    list5 = list3;
                }
                Object obj4 = map.get("filesize");
                List list6 = obj4 instanceof List ? (List) obj4 : null;
                if (list6 != null) {
                    list3 = list6;
                }
                ArrayList arrayList = new ArrayList();
                int i7 = 0;
                for (Object obj5 : list) {
                    int i8 = i7 + 1;
                    if (i7 < 0) {
                        AbstractC3252r.F();
                        throw null;
                    }
                    String str = (String) obj5;
                    Object objH02 = AbstractC3251q.h0(i7, list4);
                    if (objH02 instanceof Boolean ? ((Boolean) objH02).booleanValue() : !(objH02 instanceof Number) ? !((objH02 instanceof String) && (w.t0((String) objH02, "true", true) || o.c(objH02, "1"))) : ((Number) objH02).intValue() == 0) {
                        Object objH03 = AbstractC3251q.h0(i7, list5);
                        String str2 = (objH03 == null || (string = objH03.toString()) == null || !P2.c.e(string)) ? null : string;
                        Object objH04 = AbstractC3251q.h0(i7, list3);
                        arrayList.add(new N2.f(str, "premiumize", null, str2, null, objH04 instanceof Number ? ((Number) objH04).longValue() : (!(objH04 instanceof String) || (lC0 = w.C0((String) objH04)) == null) ? 0L : lC0.longValue(), null, null, 67108820));
                    }
                    i7 = i8;
                }
                return arrayList;
            default:
                B4.a aVar2 = B4.a.f492a;
                int i9 = this.f6048b;
                if (i9 == 0) {
                    AbstractC2467b.l(obj);
                    Map mapW = AbstractC3229F.w(new k("hash", AbstractC3251q.m0(this.f6049c, ",", null, null, null, 62)), new k("format", "object"), new k("list_files", "true"));
                    Map mapR = A0.a.r("Authorization", "Bearer " + this.f6050d);
                    this.f6048b = 1;
                    objH0 = C.h0("https://api.torbox.app/v1/api/torrents/checkcached", mapW, mapR, this.f6051e, this);
                    if (objH0 == aVar2) {
                        return aVar2;
                    }
                } else {
                    if (i9 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    AbstractC2467b.l(obj);
                    objH0 = obj;
                }
                Map map2 = (Map) objH0;
                z zVar2 = z.f26066a;
                if (map2 == null) {
                    map2 = zVar2;
                }
                Object obj6 = map2.get("data");
                Map map3 = obj6 instanceof Map ? (Map) obj6 : null;
                return map3 == null ? zVar2 : map3;
        }
    }
}
