package ඓ.ⁱ.K.ʬ;

import com.appsflyer.share.Constants;
import com.facebook.GraphRequest;
import com.qiniu.android.http.CancellationHandler;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
import org.json.JSONObject;
import ඓ.ⁱ.K.ʬ.C1232;
import ඓ.ⁱ.K.ඓ.C1250;
import ඓ.ⁱ.K.㸾.C1276;
import ῲ.ᨨ.㳳.C1841;
import 㿎.AbstractC2537;
import 㿎.AbstractC2651;
import 㿎.AbstractC2660;
import 㿎.C2531;
import 㿎.C2625;
import 㿎.C2628;
import 㿎.C2642;
import 㿎.C2644;
import 㿎.C2671;

/* renamed from: ඓ.ⁱ.K.ʬ.㸾  reason: contains not printable characters */
/* compiled from: Client */
public final class C1243 {

    /* renamed from: K  reason: contains not printable characters */
    public C2625 f4888;

    /* renamed from: ඓ.ⁱ.K.ʬ.㸾$ῲ  reason: contains not printable characters */
    /* compiled from: Client */
    public class C1245 implements AbstractC2660 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final /* synthetic */ long f4891;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ C1276 f4892;

        /* renamed from: K  reason: contains not printable characters */
        public final /* synthetic */ C1244 f4893;

        /* renamed from: 㸾  reason: contains not printable characters */
        public final /* synthetic */ AbstractC1242 f4894;

        public C1245(C1243 r1, C1244 r2, C1276 r3, long j, AbstractC1242 r6) {
            this.f4893 = r2;
            this.f4892 = r3;
            this.f4891 = j;
            this.f4894 = r6;
        }

        @Override // 㿎.AbstractC2660
        public void onFailure(AbstractC2537 r21, IOException iOException) {
            int i;
            iOException.printStackTrace();
            String message = iOException.getMessage();
            if (iOException instanceof CancellationHandler.CancellationException) {
                i = -2;
            } else if (iOException instanceof UnknownHostException) {
                i = -1003;
            } else if (message != null && message.indexOf("Broken pipe") == 0) {
                i = -1005;
            } else if (iOException instanceof SocketTimeoutException) {
                i = -1001;
            } else {
                i = iOException instanceof ConnectException ? -1004 : -1;
            }
            C2531 r2 = ((C2642) r21).f8975.f8985;
            this.f4894.m3312(C1248.m3321(null, i, "", "", "", r2.f8542, r2.m6595(), "", r2.f8536, this.f4893.f4889, -1, iOException.getMessage(), this.f4892, this.f4891), null);
        }

        /* JADX WARNING: Removed duplicated region for block: B:33:0x00b4  */
        /* JADX WARNING: Removed duplicated region for block: B:42:0x00d9  */
        /* JADX WARNING: Removed duplicated region for block: B:45:0x00e7  */
        /* JADX WARNING: Removed duplicated region for block: B:48:0x00ef  */
        /* JADX WARNING: Removed duplicated region for block: B:61:0x011f A[Catch:{ all -> 0x0127 }] */
        /* JADX WARNING: Removed duplicated region for block: B:62:0x0122 A[Catch:{ all -> 0x0127 }] */
        @Override // 㿎.AbstractC2660
        public void onResponse(AbstractC2537 r24, C2671 r25) throws IOException {
            String str;
            String str2;
            byte[] bArr;
            String str3;
            String str4;
            JSONObject jSONObject;
            String str5;
            String r7;
            String r8;
            long j;
            String str6;
            Exception e;
            C1244 r0 = (C1244) Object.class.cast(r25.f9087.f8983.get(Object.class));
            String str7 = r0.f4890;
            long j2 = r0.f4889;
            C1276 r15 = this.f4892;
            long j3 = this.f4891;
            AbstractC1242 r10 = this.f4894;
            int i = r25.f9092;
            String r02 = r25.f9088.m6996("X-Reqid");
            if (r02 == null) {
                r02 = null;
            }
            if (r02 == null) {
                str = null;
            } else {
                str = r02.trim().split(",")[0];
            }
            try {
                bArr = r25.f9093.bytes();
                str2 = null;
            } catch (IOException e2) {
                str2 = e2.getMessage();
                bArr = null;
            }
            C2628 contentType = r25.f9093.contentType();
            if (contentType == null) {
                str4 = "";
                str3 = str2;
            } else {
                StringBuilder sb = new StringBuilder();
                str3 = str2;
                sb.append(contentType.f8932);
                sb.append(Constants.URL_PATH_DELIMITER);
                sb.append(contentType.f8931);
                str4 = sb.toString();
            }
            if (!str4.equals("application/json") || bArr == null) {
                if (bArr == null) {
                    str5 = "null body";
                } else {
                    str5 = new String(bArr);
                }
                jSONObject = null;
            } else {
                try {
                    String str8 = new String(bArr, "utf-8");
                    if ("".equals(str8)) {
                        jSONObject = new JSONObject();
                    } else {
                        jSONObject = new JSONObject(str8);
                    }
                    try {
                        if (r25.f9092 != 200) {
                            str6 = jSONObject.optString("error", new String(bArr, "utf-8"));
                            str3 = str6;
                        }
                    } catch (Exception e3) {
                        e = e3;
                        if (r25.f9092 < 300) {
                        }
                        str5 = str3;
                        C2531 r3 = r25.f9087.f8985;
                        r7 = r25.f9088.m6996("X-Log");
                        if (r7 == null) {
                        }
                        r8 = r25.f9088.m6996("X-Via");
                        if (r8 == null) {
                        }
                        if (r8.equals("")) {
                        }
                        String str9 = r3.f8542;
                        String r17 = r3.m6595();
                        int i2 = r3.f8536;
                        AbstractC2651 r2 = r25.f9087.f8987;
                        if (r2 == null) {
                        }
                        C1841.m4795(new RunnableC1228(r10, C1248.m3321(jSONObject, i, str, r7, r8, str9, r17, str7, i2, j2, j, str5, r15, j3)));
                    }
                } catch (Exception e4) {
                    e = e4;
                    jSONObject = null;
                    if (r25.f9092 < 300) {
                        str6 = e.getMessage();
                        str3 = str6;
                    }
                    str5 = str3;
                    C2531 r32 = r25.f9087.f8985;
                    r7 = r25.f9088.m6996("X-Log");
                    if (r7 == null) {
                    }
                    r8 = r25.f9088.m6996("X-Via");
                    if (r8 == null) {
                    }
                    if (r8.equals("")) {
                    }
                    String str92 = r32.f8542;
                    String r172 = r32.m6595();
                    int i22 = r32.f8536;
                    AbstractC2651 r22 = r25.f9087.f8987;
                    if (r22 == null) {
                    }
                    C1841.m4795(new RunnableC1228(r10, C1248.m3321(jSONObject, i, str, r7, r8, str92, r172, str7, i22, j2, j, str5, r15, j3)));
                }
                str5 = str3;
            }
            C2531 r322 = r25.f9087.f8985;
            r7 = r25.f9088.m6996("X-Log");
            if (r7 == null) {
                r7 = null;
            }
            r8 = r25.f9088.m6996("X-Via");
            if (r8 == null) {
                r8 = "";
            }
            if (r8.equals("")) {
                r8 = r25.f9088.m6996("X-Px");
                if (r8 == null) {
                    r8 = "";
                }
                if (r8.equals("")) {
                    r8 = r25.f9088.m6996("Fw-Via");
                    if (r8 == null) {
                        r8 = "";
                    }
                    r8.equals("");
                }
            }
            String str922 = r322.f8542;
            String r1722 = r322.m6595();
            int i222 = r322.f8536;
            try {
                AbstractC2651 r222 = r25.f9087.f8987;
                j = r222 == null ? 0 : r222.contentLength();
            } catch (Throwable unused) {
                j = -1;
            }
            C1841.m4795(new RunnableC1228(r10, C1248.m3321(jSONObject, i, str, r7, r8, str922, r1722, str7, i222, j2, j, str5, r15, j3)));
        }
    }

    /* renamed from: ඓ.ⁱ.K.ʬ.㸾$K  reason: contains not printable characters */
    /* compiled from: Client */
    public class C1246 implements C1250.AbstractC1251 {

        /* renamed from: K  reason: contains not printable characters */
        public final /* synthetic */ C2644.C2645 f4895;

        public C1246(C1243 r1, C2644.C2645 k) {
            this.f4895 = k;
        }

        @Override // ඓ.ⁱ.K.ඓ.C1250.AbstractC1251
        /* renamed from: K  reason: contains not printable characters */
        public void m3317(String str, Object obj) {
            this.f4895.m6966(str, obj.toString());
        }
    }

    public C1243(int i, int i2) {
        C2625.C2626 r0 = new C2625.C2626();
        r0.f8923.add(new C1235(this));
        r0.m6924((long) i, TimeUnit.SECONDS);
        r0.m6923((long) i2, TimeUnit.SECONDS);
        r0.m6922(0, TimeUnit.SECONDS);
        this.f4888 = new C2625(r0);
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m3316(C2644.C2645 k, C1250 r10, C1276 r11, long j, AbstractC1242 r14) {
        if (r10 != null) {
            r10.m3327(new C1246(this, k));
        }
        if (r11 != null) {
            k.m6966(GraphRequest.USER_AGENT_HEADER, C1229.f4859.m3303(r11.f4989));
        } else {
            k.m6966(GraphRequest.USER_AGENT_HEADER, C1229.f4859.m3303("pandora"));
        }
        C1244 r3 = new C1244(null);
        C2625 r102 = this.f4888;
        k.m6964(r3);
        ((C2642) r102.m6920(k.m6970())).m6957(new C1245(this, r3, r11, j, r14));
    }

    /* renamed from: ඓ.ⁱ.K.ʬ.㸾$ʬ  reason: contains not printable characters */
    /* compiled from: Client */
    public static class C1244 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public long f4889 = -1;

        /* renamed from: K  reason: contains not printable characters */
        public String f4890 = "";

        public C1244() {
        }

        public /* synthetic */ C1244(C1239 k) {
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m3315(String str, byte[] bArr, int i, int i2, C1250 r14, C1276 r15, long j, AbstractC1231 r18, AbstractC1242 r19, CancellationHandler cancellationHandler) {
        AbstractC2651 r0;
        Object obj;
        if (bArr == null || bArr.length <= 0) {
            r0 = AbstractC2651.create((C2628) null, new byte[0]);
        } else {
            C2628 r1 = C2628.m6936("application/octet-stream");
            if (!(r14 == null || (obj = r14.f4922.get(GraphRequest.CONTENT_TYPE_HEADER)) == null)) {
                r1 = C2628.m6936(obj.toString());
            }
            r0 = AbstractC2651.create(r1, bArr, i, i2);
        }
        C1236 r4 = r0;
        if (!(r18 == null && cancellationHandler == null)) {
            r4 = new C1236(r4, r18, j, cancellationHandler);
        }
        C2644.C2645 k = new C2644.C2645();
        k.m6965(str);
        k.m6967("POST", r4);
        m3316(k, r14, r15, j, r19);
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m3313(String str, C1241 r13, C1276 r14, AbstractC1231 r15, AbstractC1242 r16, CancellationHandler cancellationHandler) {
        long j;
        AbstractC2651 r1;
        AbstractC2651 r10;
        if (r13.f4885 != null) {
            r1 = AbstractC2651.create(C2628.m6936(r13.f4884), r13.f4885);
            j = r13.f4885.length();
        } else {
            r1 = AbstractC2651.create(C2628.m6936(r13.f4884), r13.f4886);
            j = (long) r13.f4886.length;
        }
        C1250 r4 = r13.f4883;
        String str2 = r13.f4887;
        C1232.C1234 k = new C1232.C1234();
        k.m3309(C1232.C1233.m3307("file", str2, r1));
        r4.m3327(new C1230(this, k));
        C2628 r0 = C2628.m6936("multipart/form-data");
        if (r0 == null) {
            throw new NullPointerException("type == null");
        } else if (r0.f8932.equals("multipart")) {
            k.f4873 = r0;
            if (!k.f4874.isEmpty()) {
                C1232 r02 = new C1232(k.f4875, k.f4873, k.f4874);
                if (r15 == null && cancellationHandler == null) {
                    r10 = r02;
                } else {
                    r10 = new C1236(r02, r15, j, cancellationHandler);
                }
                C2644.C2645 k2 = new C2644.C2645();
                k2.m6965(str);
                k2.m6967("POST", r10);
                m3316(k2, null, r14, j, r16);
                return;
            }
            throw new IllegalStateException("Multipart body must have at least one part.");
        } else {
            throw new IllegalArgumentException("multipart != " + r0);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m3314(String str, C1250 r9, C1276 r10, AbstractC1242 r11) {
        C2644.C2645 k = new C2644.C2645();
        k.m6967("GET", (AbstractC2651) null);
        k.m6965(str);
        m3316(k, r9, r10, 0, r11);
    }
}
