package g;

import com.seewo.vcommons.constants.SeewoBoardKeys;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public final class v extends c0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final u f6462a = u.a("multipart/mixed");

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final u f6463b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final byte[] f6464c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final byte[] f6465d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final byte[] f6466e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final h.i f6467f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final List<b> f6469h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public long f6470i = -1;

    public static final class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final h.i f6471a;

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

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public final List<b> f6473c;

        public a() {
            String string = UUID.randomUUID().toString();
            this.f6472b = v.f6462a;
            this.f6473c = new ArrayList();
            this.f6471a = h.i.e(string);
        }
    }

    public static final class b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        @Nullable
        public final r f6474a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final c0 f6475b;

        public b(@Nullable r rVar, c0 c0Var) {
            this.f6474a = rVar;
            this.f6475b = c0Var;
        }
    }

    static {
        u.a("multipart/alternative");
        u.a("multipart/digest");
        u.a("multipart/parallel");
        f6463b = u.a("multipart/form-data");
        f6464c = new byte[]{SeewoBoardKeys.TOUCH_KEY_BOARD_F1, SeewoBoardKeys.TOUCH_KEY_BOARD_3};
        f6465d = new byte[]{13, 10};
        f6466e = new byte[]{SeewoBoardKeys.TOUCH_KEY_BOARD_MINUS, SeewoBoardKeys.TOUCH_KEY_BOARD_MINUS};
    }

    public v(h.i iVar, u uVar, List<b> list) {
        this.f6467f = iVar;
        this.f6468g = u.a(uVar + "; boundary=" + iVar.o());
        this.f6469h = g.i0.c.n(list);
    }

    @Override // g.c0
    public long a() {
        long j2 = this.f6470i;
        if (j2 != -1) {
            return j2;
        }
        long jD = d(null, true);
        this.f6470i = jD;
        return jD;
    }

    @Override // g.c0
    public u b() {
        return this.f6468g;
    }

    @Override // g.c0
    public void c(h.g gVar) {
        d(gVar, false);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final long d(@Nullable h.g gVar, boolean z) {
        h.f fVar;
        if (z) {
            gVar = new h.f();
            fVar = gVar;
        } else {
            fVar = 0;
        }
        int size = this.f6469h.size();
        long j2 = 0;
        for (int i2 = 0; i2 < size; i2++) {
            b bVar = this.f6469h.get(i2);
            r rVar = bVar.f6474a;
            c0 c0Var = bVar.f6475b;
            gVar.f(f6466e);
            gVar.t(this.f6467f);
            gVar.f(f6465d);
            if (rVar != null) {
                int iG = rVar.g();
                for (int i3 = 0; i3 < iG; i3++) {
                    gVar.C(rVar.d(i3)).f(f6464c).C(rVar.h(i3)).f(f6465d);
                }
            }
            u uVarB = c0Var.b();
            if (uVarB != null) {
                gVar.C("Content-Type: ").C(uVarB.f6459c).f(f6465d);
            }
            long jA = c0Var.a();
            if (jA != -1) {
                gVar.C("Content-Length: ").D(jA).f(f6465d);
            } else if (z) {
                fVar.K();
                return -1L;
            }
            byte[] bArr = f6465d;
            gVar.f(bArr);
            if (z) {
                j2 += jA;
            } else {
                c0Var.c(gVar);
            }
            gVar.f(bArr);
        }
        byte[] bArr2 = f6466e;
        gVar.f(bArr2);
        gVar.t(this.f6467f);
        gVar.f(bArr2);
        gVar.f(f6465d);
        if (!z) {
            return j2;
        }
        long j3 = j2 + fVar.f6529d;
        fVar.K();
        return j3;
    }
}
