package p491;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p447.AbstractC6930;
import p447.AbstractC6936;
import p447.C6898;
import p447.C6908;
import p447.C6914;
import p447.C6916;
import p447.C6926;
import p447.C6933;
import p447.InterfaceC6868;
import p447.InterfaceC6870;
import p461.AbstractC7111;
import p461.C7103;
import p461.InterfaceC7107;
import p461.InterfaceC7129;
import p491.C7362;

/* JADX INFO: renamed from: ޓ.ޑ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C7339<T> implements InterfaceC7310<T> {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C7364 f21249;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final Object[] f21250;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final InterfaceC6868.InterfaceC6869 f21251;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final InterfaceC7320<AbstractC6936, T> f21252;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public volatile boolean f21253;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    @GuardedBy("this")
    @Nullable
    public InterfaceC6868 f21254;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    @GuardedBy("this")
    @Nullable
    public Throwable f21255;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    @GuardedBy("this")
    public boolean f21256;

    /* JADX INFO: renamed from: ޓ.ޑ$֏, reason: contains not printable characters */
    public class C7340 implements InterfaceC6870 {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final /* synthetic */ InterfaceC7313 f21257;

        public C7340(InterfaceC7313 interfaceC7313) {
            this.f21257 = interfaceC7313;
        }

        @Override // p447.InterfaceC6870
        /* JADX INFO: renamed from: ֏ */
        public void mo4971(InterfaceC6868 interfaceC6868, IOException iOException) {
            try {
                this.f21257.mo10957(C7339.this, iOException);
            } catch (Throwable th) {
                C7373.m10995(th);
                th.printStackTrace();
            }
        }

        @Override // p447.InterfaceC6870
        /* JADX INFO: renamed from: ֏ */
        public void mo4972(InterfaceC6868 interfaceC6868, C6933 c6933) {
            try {
                try {
                    this.f21257.mo10958(C7339.this, C7339.this.m10963(c6933));
                } catch (Throwable th) {
                    C7373.m10995(th);
                    th.printStackTrace();
                }
            } catch (Throwable th2) {
                C7373.m10995(th2);
                try {
                    this.f21257.mo10957(C7339.this, th2);
                } catch (Throwable th3) {
                    C7373.m10995(th3);
                    th3.printStackTrace();
                }
            }
        }
    }

    /* JADX INFO: renamed from: ޓ.ޑ$ؠ, reason: contains not printable characters */
    public static final class C7341 extends AbstractC6936 {

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final AbstractC6936 f21259;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final InterfaceC7107 f21260;

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        @Nullable
        public IOException f21261;

        /* JADX INFO: renamed from: ޓ.ޑ$ؠ$֏, reason: contains not printable characters */
        public class C7342 extends AbstractC7111 {
            public C7342(InterfaceC7129 interfaceC7129) {
                super(interfaceC7129);
            }

            @Override // p461.AbstractC7111, p461.InterfaceC7129
            /* JADX INFO: renamed from: ؠ */
            public long mo10207(C7103 c7103, long j) throws IOException {
                try {
                    return super.mo10207(c7103, j);
                } catch (IOException e) {
                    C7341.this.f21261 = e;
                    throw e;
                }
            }
        }

        public C7341(AbstractC6936 abstractC6936) {
            this.f21259 = abstractC6936;
            this.f21260 = C4303.m7076((InterfaceC7129) new C7342(abstractC6936.mo10137()));
        }

        @Override // p447.AbstractC6936, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            this.f21259.close();
        }

        @Override // p447.AbstractC6936
        /* JADX INFO: renamed from: ֏ */
        public long mo10135() {
            return this.f21259.mo10135();
        }

        @Override // p447.AbstractC6936
        /* JADX INFO: renamed from: ؠ */
        public C6914 mo10136() {
            return this.f21259.mo10136();
        }

        @Override // p447.AbstractC6936
        /* JADX INFO: renamed from: ހ */
        public InterfaceC7107 mo10137() {
            return this.f21260;
        }
    }

    /* JADX INFO: renamed from: ޓ.ޑ$ހ, reason: contains not printable characters */
    public static final class C7343 extends AbstractC6936 {

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        @Nullable
        public final C6914 f21263;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final long f21264;

        public C7343(@Nullable C6914 c6914, long j) {
            this.f21263 = c6914;
            this.f21264 = j;
        }

        @Override // p447.AbstractC6936
        /* JADX INFO: renamed from: ֏ */
        public long mo10135() {
            return this.f21264;
        }

        @Override // p447.AbstractC6936
        /* JADX INFO: renamed from: ؠ */
        public C6914 mo10136() {
            return this.f21263;
        }

        @Override // p447.AbstractC6936
        /* JADX INFO: renamed from: ހ */
        public InterfaceC7107 mo10137() {
            throw new IllegalStateException("Cannot read raw response body of a converted body.");
        }
    }

    public C7339(C7364 c7364, Object[] objArr, InterfaceC6868.InterfaceC6869 interfaceC6869, InterfaceC7320<AbstractC6936, T> interfaceC7320) {
        this.f21249 = c7364;
        this.f21250 = objArr;
        this.f21251 = interfaceC6869;
        this.f21252 = interfaceC7320;
    }

    @Override // p491.InterfaceC7310
    public void cancel() {
        InterfaceC6868 interfaceC6868;
        this.f21253 = true;
        synchronized (this) {
            interfaceC6868 = this.f21254;
        }
        if (interfaceC6868 != null) {
            interfaceC6868.cancel();
        }
    }

    public Object clone() {
        return new C7339(this.f21249, this.f21250, this.f21251, this.f21252);
    }

    @Override // p491.InterfaceC7310
    /* JADX INFO: renamed from: clone */
    public InterfaceC7310 mo10959clone() {
        return new C7339(this.f21249, this.f21250, this.f21251, this.f21252);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C7366<T> m10963(C6933 c6933) throws IOException {
        AbstractC6936 abstractC6936 = c6933.f20152;
        C6933.C6934 c6934 = new C6933.C6934(c6933);
        c6934.f20165 = new C7343(abstractC6936.mo10136(), abstractC6936.mo10135());
        C6933 c6933M10133 = c6934.m10133();
        int i = c6933M10133.f20149;
        if (i < 200 || i >= 300) {
            try {
                AbstractC6936 abstractC6936M10994 = C7373.m10994(abstractC6936);
                Objects.requireNonNull(abstractC6936M10994, "body == null");
                Objects.requireNonNull(c6933M10133, "rawResponse == null");
                if (c6933M10133.m10127()) {
                    throw new IllegalArgumentException("rawResponse should not be successful response");
                }
                return new C7366<>(c6933M10133, null, abstractC6936M10994);
            } finally {
                abstractC6936.close();
            }
        }
        if (i == 204 || i == 205) {
            abstractC6936.close();
            return C7366.m10976(null, c6933M10133);
        }
        C7341 c7341 = new C7341(abstractC6936);
        try {
            return C7366.m10976(this.f21252.mo10949(c7341), c6933M10133);
        } catch (RuntimeException e) {
            IOException iOException = c7341.f21261;
            if (iOException == null) {
                throw e;
            }
            throw iOException;
        }
    }

    @Override // p491.InterfaceC7310
    /* JADX INFO: renamed from: ֏ */
    public void mo10950(InterfaceC7313<T> interfaceC7313) {
        InterfaceC6868 interfaceC6868;
        Throwable th;
        Objects.requireNonNull(interfaceC7313, "callback == null");
        synchronized (this) {
            if (this.f21256) {
                throw new IllegalStateException("Already executed.");
            }
            this.f21256 = true;
            interfaceC6868 = this.f21254;
            th = this.f21255;
            if (interfaceC6868 == null && th == null) {
                try {
                    InterfaceC6868 interfaceC6868M10964 = m10964();
                    this.f21254 = interfaceC6868M10964;
                    interfaceC6868 = interfaceC6868M10964;
                } catch (Throwable th2) {
                    th = th2;
                    C7373.m10995(th);
                    this.f21255 = th;
                }
            }
        }
        if (th != null) {
            interfaceC7313.mo10957(this, th);
            return;
        }
        if (this.f21253) {
            interfaceC6868.cancel();
        }
        interfaceC6868.mo10024(new C7340(interfaceC7313));
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final InterfaceC6868 m10964() {
        C6908 c6908M10082;
        InterfaceC6868.InterfaceC6869 interfaceC6869 = this.f21251;
        C7364 c7364 = this.f21249;
        Object[] objArr = this.f21250;
        AbstractC7348<?>[] abstractC7348Arr = c7364.f21329;
        int length = objArr.length;
        if (length != abstractC7348Arr.length) {
            throw new IllegalArgumentException(C2803.m4882(C2803.m4896("Argument count (", length, ") doesn't match expected count ("), abstractC7348Arr.length, ")"));
        }
        C7362 c7362 = new C7362(c7364.f21322, c7364.f21321, c7364.f21323, c7364.f21324, c7364.f21325, c7364.f21326, c7364.f21327, c7364.f21328);
        if (c7364.f21330) {
            length--;
        }
        ArrayList arrayList = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            arrayList.add(objArr[i]);
            abstractC7348Arr[i].mo10966(c7362, objArr[i]);
        }
        C6908.C6909 c6909 = c7362.f21310;
        if (c6909 != null) {
            c6908M10082 = c6909.m10092();
        } else {
            c6908M10082 = c7362.f21308.m10082(c7362.f21309);
            if (c6908M10082 == null) {
                StringBuilder sbM4889 = C2803.m4889("Malformed URL. Base: ");
                sbM4889.append(c7362.f21308);
                sbM4889.append(", Relative: ");
                sbM4889.append(c7362.f21309);
                throw new IllegalArgumentException(sbM4889.toString());
            }
        }
        AbstractC6930 c7363 = c7362.f21317;
        if (c7363 == null) {
            C6898.C6899 c6899 = c7362.f21316;
            if (c6899 != null) {
                c7363 = new C6898(c6899.f19998, c6899.f19999);
            } else {
                C6916.C6917 c6917 = c7362.f21315;
                if (c6917 != null) {
                    c7363 = c6917.m10110();
                } else if (c7362.f21314) {
                    c7363 = AbstractC6930.Companion.m10125(new byte[0], null, 0, 0);
                }
            }
        }
        C6914 c6914 = c7362.f21313;
        if (c6914 != null) {
            if (c7363 != null) {
                c7363 = new C7362.C7363(c7363, c6914);
            } else {
                c7362.f21312.m10072("Content-Type", c6914.f20035);
            }
        }
        C6926.C6927 c6927 = c7362.f21311;
        c6927.f20133 = c6908M10082;
        c6927.m10121(c7362.f21312.m10073());
        c6927.m10120(c7362.f21307, c7363);
        c6927.m10117((Class<? super C7330>) C7330.class, new C7330(c7364.f21320, arrayList));
        InterfaceC6868 interfaceC6868Mo10028 = interfaceC6869.mo10028(c6927.m10123());
        if (interfaceC6868Mo10028 != null) {
            return interfaceC6868Mo10028;
        }
        throw new NullPointerException("Call.Factory returned null.");
    }

    @GuardedBy("this")
    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final InterfaceC6868 m10965() throws IOException {
        InterfaceC6868 interfaceC6868 = this.f21254;
        if (interfaceC6868 != null) {
            return interfaceC6868;
        }
        Throwable th = this.f21255;
        if (th != null) {
            if (th instanceof IOException) {
                throw ((IOException) th);
            }
            if (th instanceof RuntimeException) {
                throw ((RuntimeException) th);
            }
            throw ((Error) th);
        }
        try {
            InterfaceC6868 interfaceC6868M10964 = m10964();
            this.f21254 = interfaceC6868M10964;
            return interfaceC6868M10964;
        } catch (IOException | Error | RuntimeException e) {
            C7373.m10995(e);
            this.f21255 = e;
            throw e;
        }
    }

    @Override // p491.InterfaceC7310
    /* JADX INFO: renamed from: ރ */
    public C7366<T> mo10951() {
        InterfaceC6868 interfaceC6868M10965;
        synchronized (this) {
            if (this.f21256) {
                throw new IllegalStateException("Already executed.");
            }
            this.f21256 = true;
            interfaceC6868M10965 = m10965();
        }
        if (this.f21253) {
            interfaceC6868M10965.cancel();
        }
        return m10963(interfaceC6868M10965.mo10025());
    }

    @Override // p491.InterfaceC7310
    /* JADX INFO: renamed from: ބ */
    public synchronized C6926 mo10952() {
        try {
        } catch (IOException e) {
            throw new RuntimeException("Unable to create request.", e);
        }
        return m10965().mo10026();
    }

    @Override // p491.InterfaceC7310
    /* JADX INFO: renamed from: ޅ */
    public boolean mo10953() {
        boolean z = true;
        if (this.f21253) {
            return true;
        }
        synchronized (this) {
            if (this.f21254 == null || !this.f21254.mo10027()) {
                z = false;
            }
        }
        return z;
    }
}
