package l;

import java.io.IOException;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;

/* JADX INFO: compiled from: RequestBuilder.java */
/* JADX INFO: loaded from: classes.dex */
public final class z {
    public static final char[] a = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Pattern f5097b = Pattern.compile("(.*/)?(\\.|%2e|%2E){1,2}(/.*)?");

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f5098c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final HttpUrl f5099d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    @Nullable
    public String f5100e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    @Nullable
    public HttpUrl.Builder f5101f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Request.Builder f5102g = new Request.Builder();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final Headers.Builder f5103h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    @Nullable
    public MediaType f5104i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final boolean f5105j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    @Nullable
    public MultipartBody.Builder f5106k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    @Nullable
    public FormBody.Builder f5107l;

    @Nullable
    public RequestBody m;

    /* JADX INFO: compiled from: RequestBuilder.java */
    public static class a extends RequestBody {
        public final RequestBody a;

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

        public a(RequestBody requestBody, MediaType mediaType) {
            this.a = requestBody;
            this.f5108b = mediaType;
        }

        @Override // okhttp3.RequestBody
        public long contentLength() throws IOException {
            return this.a.contentLength();
        }

        @Override // okhttp3.RequestBody
        public MediaType contentType() {
            return this.f5108b;
        }

        @Override // okhttp3.RequestBody
        public void writeTo(j.f fVar) throws IOException {
            this.a.writeTo(fVar);
        }
    }

    public z(String str, HttpUrl httpUrl, @Nullable String str2, @Nullable Headers headers, @Nullable MediaType mediaType, boolean z, boolean z2, boolean z3) {
        this.f5098c = str;
        this.f5099d = httpUrl;
        this.f5100e = str2;
        this.f5104i = mediaType;
        this.f5105j = z;
        if (headers != null) {
            this.f5103h = headers.newBuilder();
        } else {
            this.f5103h = new Headers.Builder();
        }
        if (z2) {
            this.f5107l = new FormBody.Builder();
        } else if (z3) {
            MultipartBody.Builder builder = new MultipartBody.Builder();
            this.f5106k = builder;
            builder.setType(MultipartBody.FORM);
        }
    }

    public void a(String str, String str2) {
        if (!"Content-Type".equalsIgnoreCase(str)) {
            this.f5103h.add(str, str2);
            return;
        }
        try {
            this.f5104i = MediaType.get(str2);
        } catch (IllegalArgumentException e2) {
            throw new IllegalArgumentException(d.b.a.a.a.p("Malformed content type: ", str2), e2);
        }
    }

    public void b(String str, @Nullable String str2, boolean z) {
        String str3 = this.f5100e;
        if (str3 != null) {
            HttpUrl.Builder builderNewBuilder = this.f5099d.newBuilder(str3);
            this.f5101f = builderNewBuilder;
            if (builderNewBuilder == null) {
                StringBuilder sbB = d.b.a.a.a.B("Malformed URL. Base: ");
                sbB.append(this.f5099d);
                sbB.append(", Relative: ");
                sbB.append(this.f5100e);
                throw new IllegalArgumentException(sbB.toString());
            }
            this.f5100e = null;
        }
        if (z) {
            this.f5101f.addEncodedQueryParameter(str, str2);
        } else {
            this.f5101f.addQueryParameter(str, str2);
        }
    }
}
