package coil.network;

import coil.util.Utils;
import m1.g;
import okhttp3.CacheControl;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.Response;
import p5.InterfaceC2741k;
import p5.InterfaceC2742l;
import w4.h;
import w4.i;

/* JADX INFO: loaded from: classes.dex */
public final class CacheResponse {
    private final h cacheControl$delegate;
    private final h contentType$delegate;
    private final boolean isTls;
    private final long receivedResponseAtMillis;
    private final Headers responseHeaders;
    private final long sentRequestAtMillis;

    public CacheResponse(InterfaceC2742l interfaceC2742l) {
        i iVar = i.f25467c;
        final int i6 = 0;
        this.cacheControl$delegate = g.j(iVar, new J4.a(this) { // from class: coil.network.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ CacheResponse f13548b;

            {
                this.f13548b = this;
            }

            @Override // J4.a
            public final Object invoke() {
                switch (i6) {
                    case 0:
                        return CacheResponse.cacheControl_delegate$lambda$0(this.f13548b);
                    default:
                        return CacheResponse.contentType_delegate$lambda$1(this.f13548b);
                }
            }
        });
        final int i7 = 1;
        this.contentType$delegate = g.j(iVar, new J4.a(this) { // from class: coil.network.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ CacheResponse f13548b;

            {
                this.f13548b = this;
            }

            @Override // J4.a
            public final Object invoke() {
                switch (i7) {
                    case 0:
                        return CacheResponse.cacheControl_delegate$lambda$0(this.f13548b);
                    default:
                        return CacheResponse.contentType_delegate$lambda$1(this.f13548b);
                }
            }
        });
        this.sentRequestAtMillis = Long.parseLong(interfaceC2742l.s());
        this.receivedResponseAtMillis = Long.parseLong(interfaceC2742l.s());
        this.isTls = Integer.parseInt(interfaceC2742l.s()) > 0;
        int i8 = Integer.parseInt(interfaceC2742l.s());
        Headers.Builder builder = new Headers.Builder();
        for (int i9 = 0; i9 < i8; i9++) {
            Utils.addUnsafeNonAscii(builder, interfaceC2742l.s());
        }
        this.responseHeaders = builder.e();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final CacheControl cacheControl_delegate$lambda$0(CacheResponse cacheResponse) {
        CacheControl.Companion companion = CacheControl.f21927n;
        Headers headers = cacheResponse.responseHeaders;
        companion.getClass();
        return CacheControl.Companion.a(headers);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final MediaType contentType_delegate$lambda$1(CacheResponse cacheResponse) {
        String strG = cacheResponse.responseHeaders.g("Content-Type");
        if (strG == null) {
            return null;
        }
        MediaType.f22043d.getClass();
        return MediaType.Companion.b(strG);
    }

    public final CacheControl getCacheControl() {
        return (CacheControl) this.cacheControl$delegate.getValue();
    }

    public final MediaType getContentType() {
        return (MediaType) this.contentType$delegate.getValue();
    }

    public final long getReceivedResponseAtMillis() {
        return this.receivedResponseAtMillis;
    }

    public final Headers getResponseHeaders() {
        return this.responseHeaders;
    }

    public final long getSentRequestAtMillis() {
        return this.sentRequestAtMillis;
    }

    public final boolean isTls() {
        return this.isTls;
    }

    public final void writeTo(InterfaceC2741k interfaceC2741k) {
        interfaceC2741k.w(this.sentRequestAtMillis).h(10);
        interfaceC2741k.w(this.receivedResponseAtMillis).h(10);
        interfaceC2741k.w(this.isTls ? 1L : 0L).h(10);
        interfaceC2741k.w(this.responseHeaders.size()).h(10);
        int size = this.responseHeaders.size();
        for (int i6 = 0; i6 < size; i6++) {
            interfaceC2741k.n(this.responseHeaders.h(i6)).n(": ").n(this.responseHeaders.l(i6)).h(10);
        }
    }

    public CacheResponse(Response response) {
        i iVar = i.f25467c;
        final int i6 = 0;
        this.cacheControl$delegate = g.j(iVar, new J4.a(this) { // from class: coil.network.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ CacheResponse f13548b;

            {
                this.f13548b = this;
            }

            @Override // J4.a
            public final Object invoke() {
                switch (i6) {
                    case 0:
                        return CacheResponse.cacheControl_delegate$lambda$0(this.f13548b);
                    default:
                        return CacheResponse.contentType_delegate$lambda$1(this.f13548b);
                }
            }
        });
        final int i7 = 1;
        this.contentType$delegate = g.j(iVar, new J4.a(this) { // from class: coil.network.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ CacheResponse f13548b;

            {
                this.f13548b = this;
            }

            @Override // J4.a
            public final Object invoke() {
                switch (i7) {
                    case 0:
                        return CacheResponse.cacheControl_delegate$lambda$0(this.f13548b);
                    default:
                        return CacheResponse.contentType_delegate$lambda$1(this.f13548b);
                }
            }
        });
        this.sentRequestAtMillis = response.f22149n;
        this.receivedResponseAtMillis = response.f22150o;
        this.isTls = response.f22144e != null;
        this.responseHeaders = response.f22145f;
    }
}
