package okhttp3;

import S4.w;
import java.io.EOFException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import kotlin.jvm.internal.o;
import okhttp3.CacheControl;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.internal.Util;
import okhttp3.internal.http.HttpMethod;
import w4.k;
import x4.AbstractC3229F;
import x4.AbstractC3252r;
import x4.z;

/* JADX INFO: loaded from: classes3.dex */
public final class Request {

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

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Map f22129e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public CacheControl f22130f;

    public static class Builder {

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

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

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public LinkedHashMap f22135e = new LinkedHashMap();

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public String f22132b = "GET";

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public Headers.Builder f22133c = new Headers.Builder();

        public final void a(String name, String value) {
            o.h(name, "name");
            o.h(value, "value");
            this.f22133c.a(name, value);
        }

        public final Request b() {
            Map mapUnmodifiableMap;
            HttpUrl httpUrl = this.f22131a;
            if (httpUrl == null) {
                throw new IllegalStateException("url == null");
            }
            String str = this.f22132b;
            Headers headersE = this.f22133c.e();
            RequestBody requestBody = this.f22134d;
            LinkedHashMap linkedHashMap = this.f22135e;
            byte[] bArr = Util.f22179a;
            o.h(linkedHashMap, "<this>");
            if (linkedHashMap.isEmpty()) {
                mapUnmodifiableMap = z.f26066a;
            } else {
                mapUnmodifiableMap = Collections.unmodifiableMap(new LinkedHashMap(linkedHashMap));
                o.g(mapUnmodifiableMap, "{\n    Collections.unmodi…(LinkedHashMap(this))\n  }");
            }
            return new Request(httpUrl, str, headersE, requestBody, mapUnmodifiableMap);
        }

        public final void c(CacheControl cacheControl) {
            o.h(cacheControl, "cacheControl");
            String string = cacheControl.toString();
            if (string.length() == 0) {
                this.f22133c.g("Cache-Control");
            } else {
                e("Cache-Control", string);
            }
        }

        public final void d() {
            g("GET", null);
        }

        public final void e(String name, String value) {
            o.h(name, "name");
            o.h(value, "value");
            this.f22133c.h(name, value);
        }

        public final void f(Headers headers) {
            o.h(headers, "headers");
            this.f22133c = headers.j();
        }

        public final void g(String method, RequestBody requestBody) {
            o.h(method, "method");
            if (method.length() <= 0) {
                throw new IllegalArgumentException("method.isEmpty() == true");
            }
            if (requestBody == null) {
                HttpMethod httpMethod = HttpMethod.f22383a;
                if (method.equals("POST") || method.equals("PUT") || method.equals("PATCH") || method.equals("PROPPATCH") || method.equals("REPORT")) {
                    throw new IllegalArgumentException(Z0.o.o("method ", method, " must have a request body.").toString());
                }
            } else if (!HttpMethod.b(method)) {
                throw new IllegalArgumentException(Z0.o.o("method ", method, " must not have a request body.").toString());
            }
            this.f22132b = method;
            this.f22134d = requestBody;
        }

        public final void h(RequestBody$Companion$toRequestBody$2 requestBody$Companion$toRequestBody$2) {
            g("POST", requestBody$Companion$toRequestBody$2);
        }

        public final void i(String url) throws EOFException {
            o.h(url, "url");
            if (w.A0(url, "ws:", true)) {
                String strSubstring = url.substring(3);
                o.g(strSubstring, "this as java.lang.String).substring(startIndex)");
                url = "http:".concat(strSubstring);
            } else if (w.A0(url, "wss:", true)) {
                String strSubstring2 = url.substring(4);
                o.g(strSubstring2, "this as java.lang.String).substring(startIndex)");
                url = "https:".concat(strSubstring2);
            }
            HttpUrl.f22023k.getClass();
            o.h(url, "<this>");
            HttpUrl.Builder builder = new HttpUrl.Builder();
            builder.b(null, url);
            this.f22131a = builder.a();
        }
    }

    public Request(HttpUrl url, String method, Headers headers, RequestBody requestBody, Map map) {
        o.h(url, "url");
        o.h(method, "method");
        this.f22125a = url;
        this.f22126b = method;
        this.f22127c = headers;
        this.f22128d = requestBody;
        this.f22129e = map;
    }

    public final CacheControl a() {
        CacheControl cacheControl = this.f22130f;
        if (cacheControl != null) {
            return cacheControl;
        }
        CacheControl.Companion companion = CacheControl.f21927n;
        Headers headers = this.f22127c;
        companion.getClass();
        CacheControl cacheControlA = CacheControl.Companion.a(headers);
        this.f22130f = cacheControlA;
        return cacheControlA;
    }

    public final Builder b() {
        Builder builder = new Builder();
        builder.f22135e = new LinkedHashMap();
        builder.f22131a = this.f22125a;
        builder.f22132b = this.f22126b;
        builder.f22134d = this.f22128d;
        Map map = this.f22129e;
        builder.f22135e = map.isEmpty() ? new LinkedHashMap() : AbstractC3229F.I(map);
        builder.f22133c = this.f22127c.j();
        return builder;
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder("Request{method=");
        sb.append(this.f22126b);
        sb.append(", url=");
        sb.append(this.f22125a);
        Headers headers = this.f22127c;
        if (headers.size() != 0) {
            sb.append(", headers=[");
            int i6 = 0;
            for (k kVar : headers) {
                int i7 = i6 + 1;
                if (i6 < 0) {
                    AbstractC3252r.F();
                    throw null;
                }
                k kVar2 = kVar;
                String str = (String) kVar2.f25469a;
                String str2 = (String) kVar2.f25470b;
                if (i6 > 0) {
                    sb.append(", ");
                }
                sb.append(str);
                sb.append(':');
                sb.append(str2);
                i6 = i7;
            }
            sb.append(']');
        }
        Map map = this.f22129e;
        if (!map.isEmpty()) {
            sb.append(", tags=");
            sb.append(map);
        }
        sb.append('}');
        String string = sb.toString();
        o.g(string, "StringBuilder().apply(builderAction).toString()");
        return string;
    }
}
