package F7;

import d3.R0;
import d5.AbstractC0844a;
import e0.C0853a;
import java.io.IOException;
import java.util.ArrayList;
import k7.InterfaceC1112d;
import x7.C1731g;
import x7.C1734j;

/* JADX INFO: loaded from: classes.dex */
public final class B implements InterfaceC0121e {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final S f2584q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final Object f2585r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final Object[] f2586s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final InterfaceC1112d f2587t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final InterfaceC0130n f2588u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public volatile boolean f2589v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public o7.i f2590w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public Throwable f2591x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public boolean f2592y;

    public B(S s8, Object obj, Object[] objArr, InterfaceC1112d interfaceC1112d, InterfaceC0130n interfaceC0130n) {
        this.f2584q = s8;
        this.f2585r = obj;
        this.f2586s = objArr;
        this.f2587t = interfaceC1112d;
        this.f2588u = interfaceC0130n;
    }

    @Override // F7.InterfaceC0121e
    public final void a(InterfaceC0124h interfaceC0124h) {
        o7.i iVar;
        Throwable th;
        synchronized (this) {
            try {
                if (this.f2592y) {
                    throw new IllegalStateException("Already executed.");
                }
                this.f2592y = true;
                iVar = this.f2590w;
                th = this.f2591x;
                if (iVar == null && th == null) {
                    try {
                        o7.i iVarC = c();
                        this.f2590w = iVarC;
                        iVar = iVarC;
                    } catch (Throwable th2) {
                        th = th2;
                        b0.s(th);
                        this.f2591x = th;
                    }
                }
            } catch (Throwable th3) {
                throw th3;
            }
        }
        if (th != null) {
            interfaceC0124h.v(this, th);
            return;
        }
        if (this.f2589v) {
            iVar.cancel();
        }
        iVar.f(new R0(this, 15, interfaceC0124h));
    }

    @Override // F7.InterfaceC0121e
    /* JADX INFO: renamed from: b */
    public final InterfaceC0121e clone() {
        return new B(this.f2584q, this.f2585r, this.f2586s, this.f2587t, this.f2588u);
    }

    public final o7.i c() {
        k7.q qVarA;
        S s8 = this.f2584q;
        Object[] objArr = this.f2586s;
        int length = objArr.length;
        b0[] b0VarArr = s8.f2675k;
        if (length != b0VarArr.length) {
            throw new IllegalArgumentException(AbstractC0844a.n(AbstractC0844a.o(length, "Argument count (", ") doesn't match expected count ("), b0VarArr.length, ")"));
        }
        P p3 = new P(s8.f2669d, s8.f2668c, s8.f2670e, s8.f2671f, s8.f2672g, s8.f2673h, s8.i, s8.f2674j);
        if (s8.f2676l) {
            length--;
        }
        ArrayList arrayList = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            arrayList.add(objArr[i]);
            b0VarArr[i].a(p3, objArr[i]);
        }
        k7.p pVar = p3.f2634d;
        if (pVar != null) {
            qVarA = pVar.a();
        } else {
            String str = p3.f2633c;
            k7.q qVar = p3.f2632b;
            qVar.getClass();
            P6.g.e(str, "link");
            k7.p pVarF = qVar.f(str);
            qVarA = pVarF != null ? pVarF.a() : null;
            if (qVarA == null) {
                throw new IllegalArgumentException("Malformed URL. Base: " + qVar + ", Relative: " + p3.f2633c);
            }
        }
        k7.A o8 = p3.f2640k;
        if (o8 == null) {
            C0853a c0853a = p3.f2639j;
            if (c0853a != null) {
                o8 = new k7.m((ArrayList) c0853a.f12397r, (ArrayList) c0853a.f12398s);
            } else {
                com.google.android.material.datepicker.c cVar = p3.i;
                if (cVar != null) {
                    ArrayList arrayList2 = (ArrayList) cVar.f10221t;
                    if (arrayList2.isEmpty()) {
                        throw new IllegalStateException("Multipart body must have at least one part.");
                    }
                    o8 = new k7.u((C1734j) cVar.f10219r, (k7.s) cVar.f10220s, l7.b.x(arrayList2));
                } else if (p3.f2638h) {
                    long j8 = 0;
                    l7.b.c(j8, j8, j8);
                    o8 = new k7.z(null, 0, new byte[0]);
                }
            }
        }
        k7.s sVar = p3.f2637g;
        N0.c cVar2 = p3.f2636f;
        if (sVar != null) {
            if (o8 != null) {
                o8 = new O(o8, sVar);
            } else {
                cVar2.f("Content-Type", sVar.f14132a);
            }
        }
        K2.e eVar = p3.f2635e;
        eVar.getClass();
        eVar.f3552q = qVarA;
        eVar.f3554s = cVar2.i().f();
        eVar.J(p3.f2631a, o8);
        eVar.T(C0136u.class, new C0136u(s8.f2666a, this.f2585r, s8.f2667b, arrayList));
        k7.y yVarQ = eVar.q();
        k7.w wVar = (k7.w) this.f2587t;
        wVar.getClass();
        return new o7.i(wVar, yVarQ);
    }

    @Override // F7.InterfaceC0121e
    public final void cancel() {
        o7.i iVar;
        this.f2589v = true;
        synchronized (this) {
            iVar = this.f2590w;
        }
        if (iVar != null) {
            iVar.cancel();
        }
    }

    public final Object clone() {
        return new B(this.f2584q, this.f2585r, this.f2586s, this.f2587t, this.f2588u);
    }

    public final o7.i d() throws IOException {
        o7.i iVar = this.f2590w;
        if (iVar != null) {
            return iVar;
        }
        Throwable th = this.f2591x;
        if (th != null) {
            if (th instanceof IOException) {
                throw ((IOException) th);
            }
            if (th instanceof RuntimeException) {
                throw ((RuntimeException) th);
            }
            throw ((Error) th);
        }
        try {
            o7.i iVarC = c();
            this.f2590w = iVarC;
            return iVarC;
        } catch (IOException | Error | RuntimeException e8) {
            b0.s(e8);
            this.f2591x = e8;
            throw e8;
        }
    }

    public final T e(k7.C c3) throws IOException {
        k7.B bG = c3.g();
        k7.E e8 = c3.f14016w;
        bG.f14001g = new A(e8.b(), e8.a());
        k7.C cA = bG.a();
        int i = cA.f14013t;
        if (i < 200 || i >= 300) {
            try {
                C1731g c1731g = new C1731g();
                e8.g().L(c1731g);
                k7.D d8 = new k7.D(e8.b(), e8.a(), c1731g, 0);
                if (cA.b()) {
                    throw new IllegalArgumentException("rawResponse should not be successful response");
                }
                return new T(cA, null, d8);
            } finally {
                e8.close();
            }
        }
        if (i == 204 || i == 205) {
            e8.close();
            if (cA.b()) {
                return new T(cA, null, null);
            }
            throw new IllegalArgumentException("rawResponse must be successful response");
        }
        C0141z c0141z = new C0141z(e8);
        try {
            Object objO = this.f2588u.o(c0141z);
            if (cA.b()) {
                return new T(cA, objO, null);
            }
            throw new IllegalArgumentException("rawResponse must be successful response");
        } catch (RuntimeException e9) {
            IOException iOException = (IOException) c0141z.f2740t;
            if (iOException == null) {
                throw e9;
            }
            throw iOException;
        }
    }

    @Override // F7.InterfaceC0121e
    public final synchronized k7.y g() {
        try {
        } catch (IOException e8) {
            throw new RuntimeException("Unable to create request.", e8);
        }
        return d().f15970r;
    }

    @Override // F7.InterfaceC0121e
    public final boolean j() {
        boolean z8 = true;
        if (this.f2589v) {
            return true;
        }
        synchronized (this) {
            o7.i iVar = this.f2590w;
            if (iVar == null || !iVar.f15967C) {
                z8 = false;
            }
        }
        return z8;
    }
}
