package okhttp3;

import S4.p;
import S4.w;
import java.util.concurrent.TimeUnit;
import kotlin.jvm.internal.o;
import okhttp3.internal.Util;

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

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public static final Companion f21927n = new Companion(0);

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public static final CacheControl f21928o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public static final CacheControl f21929p;

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

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

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

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

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

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

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

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

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

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

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

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

    public static final class Builder {

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

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

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

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

        public final CacheControl a() {
            return new CacheControl(this.f21942a, this.f21943b, -1, -1, false, false, false, this.f21944c, -1, this.f21945d, false, false, null);
        }
    }

    public static final class Companion {
        public /* synthetic */ Companion(int i6) {
            this();
        }

        /* JADX WARN: Removed duplicated region for block: B:15:0x0048  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public static CacheControl a(Headers headers) {
            int i6;
            int i7;
            String strSubstring;
            int length;
            Headers headers2 = headers;
            o.h(headers2, "headers");
            int size = headers2.size();
            boolean z6 = true;
            boolean z7 = true;
            int i8 = 0;
            String str = null;
            boolean z8 = false;
            boolean z9 = false;
            int iZ = -1;
            int iZ2 = -1;
            boolean z10 = false;
            boolean z11 = false;
            boolean z12 = false;
            int iZ3 = -1;
            int iZ4 = -1;
            boolean z13 = false;
            boolean z14 = false;
            boolean z15 = false;
            while (i8 < size) {
                String strH = headers2.h(i8);
                String strL = headers2.l(i8);
                if (w.t0(strH, "Cache-Control", z6)) {
                    if (str == null) {
                        str = strL;
                    }
                    i6 = 0;
                    while (i6 < strL.length()) {
                        int length2 = strL.length();
                        boolean z16 = z6;
                        int length3 = i6;
                        while (true) {
                            if (length3 >= length2) {
                                i7 = size;
                                length3 = strL.length();
                                break;
                            }
                            i7 = size;
                            if (p.E0("=,;", strL.charAt(length3))) {
                                break;
                            }
                            length3++;
                            size = i7;
                        }
                        String strSubstring2 = strL.substring(i6, length3);
                        o.g(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
                        String string = p.o1(strSubstring2).toString();
                        if (length3 == strL.length() || strL.charAt(length3) == ',' || strL.charAt(length3) == ';') {
                            i6 = length3 + 1;
                            strSubstring = null;
                        } else {
                            int length4 = length3 + 1;
                            byte[] bArr = Util.f22179a;
                            int length5 = strL.length();
                            while (true) {
                                if (length4 >= length5) {
                                    length4 = strL.length();
                                    break;
                                }
                                char cCharAt = strL.charAt(length4);
                                int i9 = length5;
                                if (cCharAt != ' ' && cCharAt != '\t') {
                                    break;
                                }
                                length4++;
                                length5 = i9;
                            }
                            if (length4 >= strL.length() || strL.charAt(length4) != '\"') {
                                int length6 = strL.length();
                                int i10 = length4;
                                while (true) {
                                    if (i10 >= length6) {
                                        length = strL.length();
                                        break;
                                    }
                                    int i11 = length6;
                                    int i12 = i10;
                                    if (p.E0(",;", strL.charAt(i10))) {
                                        length = i12;
                                        break;
                                    }
                                    i10 = i12 + 1;
                                    length6 = i11;
                                }
                                String strSubstring3 = strL.substring(length4, length);
                                o.g(strSubstring3, "this as java.lang.String…ing(startIndex, endIndex)");
                                String string2 = p.o1(strSubstring3).toString();
                                i6 = length;
                                strSubstring = string2;
                            } else {
                                int i13 = length4 + 1;
                                int iN0 = p.N0(strL, '\"', i13, 4);
                                strSubstring = strL.substring(i13, iN0);
                                o.g(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
                                i6 = iN0 + 1;
                            }
                        }
                        if ("no-cache".equalsIgnoreCase(string)) {
                            z6 = z16;
                            z8 = z6;
                        } else if ("no-store".equalsIgnoreCase(string)) {
                            z6 = z16;
                            z9 = z6;
                        } else {
                            if ("max-age".equalsIgnoreCase(string)) {
                                iZ = Util.z(strSubstring, -1);
                            } else if ("s-maxage".equalsIgnoreCase(string)) {
                                iZ2 = Util.z(strSubstring, -1);
                            } else if ("private".equalsIgnoreCase(string)) {
                                z6 = z16;
                                z10 = z6;
                            } else if ("public".equalsIgnoreCase(string)) {
                                z6 = z16;
                                z11 = z6;
                            } else if ("must-revalidate".equalsIgnoreCase(string)) {
                                z6 = z16;
                                z12 = z6;
                            } else if ("max-stale".equalsIgnoreCase(string)) {
                                iZ3 = Util.z(strSubstring, Integer.MAX_VALUE);
                            } else if ("min-fresh".equalsIgnoreCase(string)) {
                                iZ4 = Util.z(strSubstring, -1);
                            } else if ("only-if-cached".equalsIgnoreCase(string)) {
                                z6 = z16;
                                z13 = z6;
                            } else if ("no-transform".equalsIgnoreCase(string)) {
                                z6 = z16;
                                z14 = z6;
                            } else if ("immutable".equalsIgnoreCase(string)) {
                                z6 = z16;
                                z15 = z6;
                            }
                            z6 = z16;
                        }
                        size = i7;
                    }
                    i8++;
                    headers2 = headers;
                    z6 = z6;
                    size = size;
                } else if (!w.t0(strH, "Pragma", z6)) {
                    i8++;
                    headers2 = headers;
                    z6 = z6;
                    size = size;
                }
                z7 = false;
                i6 = 0;
                while (i6 < strL.length()) {
                }
                i8++;
                headers2 = headers;
                z6 = z6;
                size = size;
            }
            return new CacheControl(z8, z9, iZ, iZ2, z10, z11, z12, iZ3, iZ4, z13, z14, z15, !z7 ? null : str);
        }

        private Companion() {
        }
    }

    static {
        Builder builder = new Builder();
        builder.f21942a = true;
        f21928o = builder.a();
        Builder builder2 = new Builder();
        builder2.f21945d = true;
        TimeUnit timeUnit = TimeUnit.SECONDS;
        o.h(timeUnit, "timeUnit");
        long seconds = timeUnit.toSeconds(Integer.MAX_VALUE);
        builder2.f21944c = seconds <= 2147483647L ? (int) seconds : Integer.MAX_VALUE;
        f21929p = builder2.a();
    }

    public CacheControl(boolean z6, boolean z7, int i6, int i7, boolean z8, boolean z9, boolean z10, int i8, int i9, boolean z11, boolean z12, boolean z13, String str) {
        this.f21930a = z6;
        this.f21931b = z7;
        this.f21932c = i6;
        this.f21933d = i7;
        this.f21934e = z8;
        this.f21935f = z9;
        this.f21936g = z10;
        this.f21937h = i8;
        this.f21938i = i9;
        this.f21939j = z11;
        this.f21940k = z12;
        this.l = z13;
        this.f21941m = str;
    }

    public final String toString() {
        String str = this.f21941m;
        if (str != null) {
            return str;
        }
        StringBuilder sb = new StringBuilder();
        if (this.f21930a) {
            sb.append("no-cache, ");
        }
        if (this.f21931b) {
            sb.append("no-store, ");
        }
        int i6 = this.f21932c;
        if (i6 != -1) {
            sb.append("max-age=");
            sb.append(i6);
            sb.append(", ");
        }
        int i7 = this.f21933d;
        if (i7 != -1) {
            sb.append("s-maxage=");
            sb.append(i7);
            sb.append(", ");
        }
        if (this.f21934e) {
            sb.append("private, ");
        }
        if (this.f21935f) {
            sb.append("public, ");
        }
        if (this.f21936g) {
            sb.append("must-revalidate, ");
        }
        int i8 = this.f21937h;
        if (i8 != -1) {
            sb.append("max-stale=");
            sb.append(i8);
            sb.append(", ");
        }
        int i9 = this.f21938i;
        if (i9 != -1) {
            sb.append("min-fresh=");
            sb.append(i9);
            sb.append(", ");
        }
        if (this.f21939j) {
            sb.append("only-if-cached, ");
        }
        if (this.f21940k) {
            sb.append("no-transform, ");
        }
        if (this.l) {
            sb.append("immutable, ");
        }
        if (sb.length() == 0) {
            return "";
        }
        sb.delete(sb.length() - 2, sb.length());
        String string = sb.toString();
        o.g(string, "StringBuilder().apply(builderAction).toString()");
        this.f21941m = string;
        return string;
    }
}
