package okhttp3;

import java.io.Closeable;
import kotlin.jvm.internal.o;
import okhttp3.CacheControl;
import okhttp3.Headers;
import okhttp3.internal.connection.Exchange;

/* JADX INFO: loaded from: classes3.dex */
public final class Response implements Closeable {

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final Response f22147k;
    public final Response l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final Response f22148m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final long f22149n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final long f22150o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final Exchange f22151p;

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

    public static class Builder {

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

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

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

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

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public ResponseBody f22159g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public Response f22160h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        public Response f22161i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        public Response f22162j;

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        public long f22163k;
        public long l;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public Exchange f22164m;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public int f22155c = -1;

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

        public static void b(String str, Response response) {
            if (response != null) {
                if (response.f22146j != null) {
                    throw new IllegalArgumentException(str.concat(".body != null").toString());
                }
                if (response.f22147k != null) {
                    throw new IllegalArgumentException(str.concat(".networkResponse != null").toString());
                }
                if (response.l != null) {
                    throw new IllegalArgumentException(str.concat(".cacheResponse != null").toString());
                }
                if (response.f22148m != null) {
                    throw new IllegalArgumentException(str.concat(".priorResponse != null").toString());
                }
            }
        }

        public final Response a() {
            int i6 = this.f22155c;
            if (i6 < 0) {
                throw new IllegalStateException(("code < 0: " + this.f22155c).toString());
            }
            Request request = this.f22153a;
            if (request == null) {
                throw new IllegalStateException("request == null");
            }
            Protocol protocol = this.f22154b;
            if (protocol == null) {
                throw new IllegalStateException("protocol == null");
            }
            String str = this.f22156d;
            if (str != null) {
                return new Response(request, protocol, str, i6, this.f22157e, this.f22158f.e(), this.f22159g, this.f22160h, this.f22161i, this.f22162j, this.f22163k, this.l, this.f22164m);
            }
            throw new IllegalStateException("message == null");
        }

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

    public Response(Request request, Protocol protocol, String message, int i6, Handshake handshake, Headers headers, ResponseBody responseBody, Response response, Response response2, Response response3, long j4, long j6, Exchange exchange) {
        o.h(request, "request");
        o.h(protocol, "protocol");
        o.h(message, "message");
        this.f22140a = request;
        this.f22141b = protocol;
        this.f22142c = message;
        this.f22143d = i6;
        this.f22144e = handshake;
        this.f22145f = headers;
        this.f22146j = responseBody;
        this.f22147k = response;
        this.l = response2;
        this.f22148m = response3;
        this.f22149n = j4;
        this.f22150o = j6;
        this.f22151p = exchange;
    }

    public static String b(String str, Response response) {
        response.getClass();
        String strG = response.f22145f.g(str);
        if (strG == null) {
            return null;
        }
        return strG;
    }

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

    public final boolean c() {
        int i6 = this.f22143d;
        return 200 <= i6 && i6 < 300;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        ResponseBody responseBody = this.f22146j;
        if (responseBody == null) {
            throw new IllegalStateException("response is not eligible for a body and must not be closed");
        }
        responseBody.close();
    }

    public final Builder d() {
        Builder builder = new Builder();
        builder.f22153a = this.f22140a;
        builder.f22154b = this.f22141b;
        builder.f22155c = this.f22143d;
        builder.f22156d = this.f22142c;
        builder.f22157e = this.f22144e;
        builder.f22158f = this.f22145f.j();
        builder.f22159g = this.f22146j;
        builder.f22160h = this.f22147k;
        builder.f22161i = this.l;
        builder.f22162j = this.f22148m;
        builder.f22163k = this.f22149n;
        builder.l = this.f22150o;
        builder.f22164m = this.f22151p;
        return builder;
    }

    public final String toString() {
        return "Response{protocol=" + this.f22141b + ", code=" + this.f22143d + ", message=" + this.f22142c + ", url=" + this.f22140a.f22125a + '}';
    }
}
