package C0;

import java.io.IOException;
import k4.AbstractC2400m;
import k4.InterfaceC2402o;
import k4.g0;
import k4.h0;
import k4.i0;
import m4.AbstractC2491b;
import m4.InterfaceC2492b0;
import m4.g2;
import n.C2592t;
import o0.C2631b;
import r4.C2888a;
import r4.C2889b;

/* JADX INFO: loaded from: classes.dex */
public final class D implements InterfaceC2492b0 {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Object f520c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Object f521d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Object f522e;

    public i0 b() {
        return new i0((h0) this.f521d, (String) this.f522e, (C2889b) this.f519b, (C2889b) this.f520c, this.f518a);
    }

    @Override // m4.InterfaceC2492b0
    public void close() {
        this.f518a = true;
        A4.g.t(((byte[]) this.f521d) != null, "Lack of request message. GET request is only supported for unary requests");
        ((n4.k) ((AbstractC2491b) this.f522e)).f21699o.l((g0) this.f519b, (byte[]) this.f521d);
        this.f521d = null;
        this.f519b = null;
    }

    @Override // m4.InterfaceC2492b0
    public void e(C2888a c2888a) {
        A4.g.t(((byte[]) this.f521d) == null, "writePayload should not be called multiple times");
        try {
            this.f521d = G3.g.b(c2888a);
            g2 g2Var = (g2) this.f520c;
            for (AbstractC2400m abstractC2400m : g2Var.f21042a) {
                abstractC2400m.i(0);
            }
            byte[] bArr = (byte[]) this.f521d;
            long length = bArr.length;
            long length2 = bArr.length;
            for (AbstractC2400m abstractC2400m2 : g2Var.f21042a) {
                abstractC2400m2.j(0, length, length2);
            }
            long length3 = ((byte[]) this.f521d).length;
            AbstractC2400m[] abstractC2400mArr = g2Var.f21042a;
            for (AbstractC2400m abstractC2400m3 : abstractC2400mArr) {
                abstractC2400m3.k(length3);
            }
            long length4 = ((byte[]) this.f521d).length;
            for (AbstractC2400m abstractC2400m4 : abstractC2400mArr) {
                abstractC2400m4.l(length4);
            }
        } catch (IOException e6) {
            throw new RuntimeException(e6);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public int f(T.p pVar, J0.A a6, boolean z6) {
        Object[] objArr;
        C0105f c0105f;
        int i6;
        int i7;
        I0.r rVar = (I0.r) this.f522e;
        if (this.f518a) {
            return 0;
        }
        try {
            this.f518a = true;
            C0109j c0109jS = ((B) this.f521d).s(pVar, a6);
            C2592t c2592t = (C2592t) c0109jS.f607c;
            int iH = c2592t.h();
            for (int i8 = 0; i8 < iH; i8++) {
                C0124z c0124z = (C0124z) c2592t.i(i8);
                if (!c0124z.f647d && !c0124z.f651h) {
                }
                objArr = false;
                break;
            }
            objArr = true;
            int iH2 = c2592t.h();
            int i9 = 0;
            while (true) {
                c0105f = (C0105f) this.f520c;
                if (i9 >= iH2) {
                    break;
                }
                C0124z c0124z2 = (C0124z) c2592t.i(i9);
                if (objArr != false || AbstractC0123y.b(c0124z2)) {
                    ((I0.H) this.f519b).y(c0124z2.f646c, (I0.r) this.f522e, c0124z2.f652i, true);
                    if (!rVar.f2455a.d()) {
                        c0105f.a(c0124z2.f644a, AbstractC0123y.b(c0124z2), rVar);
                        rVar.clear();
                    }
                }
                i9++;
            }
            boolean zB = c0105f.b(c0109jS, z6);
            if (c0109jS.f606b) {
                i6 = 0;
            } else {
                int iH3 = c2592t.h();
                for (int i10 = 0; i10 < iH3; i10++) {
                    C0124z c0124z3 = (C0124z) c2592t.i(i10);
                    if (!C2631b.b(AbstractC0123y.h(c0124z3, true), 0L) && c0124z3.b()) {
                        i6 = 1;
                        break;
                    }
                }
                i6 = 0;
            }
            int iH4 = c2592t.h();
            int i11 = 0;
            while (true) {
                if (i11 >= iH4) {
                    i7 = 0;
                    break;
                }
                if (((C0124z) c2592t.i(i11)).b()) {
                    i7 = 1;
                    break;
                }
                i11++;
            }
            int i12 = (zB ? 1 : 0) | (i6 << 1) | (i7 << 2);
            this.f518a = false;
            return i12;
        } catch (Throwable th) {
            this.f518a = false;
            throw th;
        }
    }

    @Override // m4.InterfaceC2492b0
    public boolean isClosed() {
        return this.f518a;
    }

    @Override // m4.InterfaceC2492b0
    public void flush() {
    }

    @Override // m4.InterfaceC2492b0
    public InterfaceC2492b0 a(boolean z6) {
        return this;
    }

    @Override // m4.InterfaceC2492b0
    public void c(int i6) {
    }

    @Override // m4.InterfaceC2492b0
    public InterfaceC2492b0 d(InterfaceC2402o interfaceC2402o) {
        return this;
    }
}
