package defpackage;

import com.strmr.ps.data.local.dao.MediaDao_Impl;
import com.strmr.ps.data.local.dao.TraktUserItemDao_Impl;
import defpackage.bn0;
import defpackage.dw7;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import kotlin.coroutines.Continuation;

/* JADX INFO: loaded from: classes3.dex */
public final /* synthetic */ class ej implements sq3 {
    public final /* synthetic */ int a;
    public final /* synthetic */ Object b;
    public final /* synthetic */ Object c;
    public final /* synthetic */ Object d;
    public final /* synthetic */ Object e;

    public /* synthetic */ ej(dw7.f fVar, sh0 sh0Var, gd4 gd4Var, gj1 gj1Var) {
        this.a = 2;
        this.d = fVar;
        this.e = sh0Var;
        this.c = gd4Var;
        this.b = gj1Var;
    }

    /* JADX WARN: Removed duplicated region for block: B:56:0x00fb  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x010c  */
    @Override // defpackage.sq3
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invoke(Object obj) throws IOException {
        pe4 pe4Var;
        BufferedInputStream bufferedInputStream;
        bn0 vs7Var;
        InputStream inputStream;
        bn0 bn0Var;
        pe4 pe4Var2;
        bn0 bn0Var2;
        String lowerCase;
        int i = this.a;
        BufferedInputStream bufferedInputStream2 = null;
        Object obj2 = null;
        bufferedInputStream2 = null;
        Object obj3 = this.e;
        Object obj4 = this.d;
        Object obj5 = this.c;
        Object obj6 = this.b;
        switch (i) {
            case 0:
                gj1 gj1Var = (gj1) obj6;
                gd4 gd4Var = (gd4) obj5;
                vy6 vy6Var = (vy6) obj4;
                ns3 ns3Var = (ns3) obj3;
                HttpURLConnection httpURLConnection = (HttpURLConnection) obj;
                int i2 = gj.i;
                cr4.g(httpURLConnection, "current");
                int responseCode = httpURLConnection.getResponseCode();
                String responseMessage = httpURLConnection.getResponseMessage();
                if (responseMessage != null) {
                    pe4Var = new pe4(responseCode, responseMessage);
                } else {
                    pe4 pe4Var3 = (pe4) pe4.t.get(Integer.valueOf(responseCode));
                    if (pe4Var3 == null) {
                        pe4Var3 = new pe4(responseCode, "Unknown Status Code");
                    }
                    pe4Var = pe4Var3;
                }
                pe4 pe4Var4 = pe4Var;
                cr4.g(gj1Var, "callContext");
                if (y41.an(Integer.valueOf(pe4.k.a), Integer.valueOf(pe4.e.a)).contains(Integer.valueOf(responseCode))) {
                    bn0.a.getClass();
                    vs7Var = bn0.a.b;
                } else {
                    try {
                        inputStream = httpURLConnection.getInputStream();
                    } catch (IOException unused) {
                        InputStream errorStream = httpURLConnection.getErrorStream();
                        if (errorStream != null) {
                            if (errorStream instanceof BufferedInputStream) {
                                bufferedInputStream = (BufferedInputStream) errorStream;
                            } else {
                                bufferedInputStream2 = new BufferedInputStream(errorStream, 8192);
                            }
                        }
                        if (bufferedInputStream2 == null) {
                        }
                    }
                    if (inputStream != null) {
                        if (inputStream instanceof BufferedInputStream) {
                            bufferedInputStream = (BufferedInputStream) inputStream;
                            bufferedInputStream2 = bufferedInputStream;
                        } else {
                            bufferedInputStream2 = new BufferedInputStream(inputStream, 8192);
                        }
                    }
                    if (bufferedInputStream2 == null) {
                        cr4.g(ql0.a, "pool");
                        vs7Var = new vs7(i15.a(bufferedInputStream2), gj1Var);
                    } else {
                        bn0.a.getClass();
                        vs7Var = bn0.a.b;
                    }
                }
                Map<String, List<String>> headerFields = httpURLConnection.getHeaderFields();
                cr4.f(headerFields, "getHeaderFields(...)");
                LinkedHashMap linkedHashMap = new LinkedHashMap(wo5.h(headerFields.size()));
                Iterator<T> it = headerFields.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry entry = (Map.Entry) it.next();
                    String str = (String) entry.getKey();
                    if (str != null) {
                        Locale locale = Locale.getDefault();
                        cr4.f(locale, "getDefault(...)");
                        lowerCase = str.toLowerCase(locale);
                        cr4.f(lowerCase, "toLowerCase(...)");
                    } else {
                        lowerCase = "";
                    }
                    linkedHashMap.put(lowerCase, entry.getValue());
                }
                LinkedHashMap linkedHashMap2 = new LinkedHashMap();
                for (Map.Entry entry2 : linkedHashMap.entrySet()) {
                    if (!n89.ab((CharSequence) entry2.getKey())) {
                        linkedHashMap2.put(entry2.getKey(), entry2.getValue());
                    }
                }
                zc4 zc4Var = zc4.f;
                l14 l14Var = new l14(linkedHashMap2);
                z28 z28Var = (z28) gd4Var.f.a(kd4.a);
                if (z28Var != null) {
                    bn0Var = vs7Var;
                    pz1 pz1VarA = z28Var.a(gd4Var, pe4Var4, l14Var, bn0Var, vy6Var, gj1Var);
                    pe4Var2 = pe4Var4;
                    if (pz1VarA != null) {
                        bn0Var2 = pz1VarA;
                    }
                    return new ud4(pe4Var2, ns3Var, l14Var, zc4Var, bn0Var2, gj1Var);
                }
                bn0Var = vs7Var;
                pe4Var2 = pe4Var4;
                bn0Var2 = bn0Var;
                return new ud4(pe4Var2, ns3Var, l14Var, zc4Var, bn0Var2, gj1Var);
            case 1:
                return ((MediaDao_Impl) obj6).lambda$appendToCategory$1((List) obj5, (List) obj4, (List) obj3, (Continuation) obj);
            case 2:
                gd4 gd4Var2 = (gd4) obj5;
                gj1 gj1Var2 = (gj1) obj6;
                try {
                    ((dw7.f) obj4).a = ((sh0) obj3).read((ByteBuffer) obj);
                    return e6a.a;
                } finally {
                    try {
                        break;
                    } catch (Throwable th) {
                    }
                }
            default:
                return ((TraktUserItemDao_Impl) obj6).lambda$replaceList$0((String) obj5, (String) obj4, (List) obj3, (Continuation) obj);
        }
    }

    public /* synthetic */ ej(Object obj, Object obj2, Object obj3, Object obj4, int i) {
        this.a = i;
        this.b = obj;
        this.c = obj2;
        this.d = obj3;
        this.e = obj4;
    }
}
