package o2;

import P6.g;
import X6.m;
import X6.n;
import android.graphics.Bitmap;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import k7.C1111c;
import k7.l;
import k7.o;
import k7.q;
import k7.y;

/* JADX INFO: renamed from: o2.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1337c {

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final long f15645h;
    public final long i;

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

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

    public C1337c(y yVar, C1336b c1336b) {
        int i;
        this.f15638a = yVar;
        this.f15639b = c1336b;
        this.f15647k = -1;
        if (c1336b != null) {
            this.f15645h = c1336b.f15634c;
            this.i = c1336b.f15635d;
            o oVar = c1336b.f15637f;
            int size = oVar.size();
            for (int i5 = 0; i5 < size; i5++) {
                String strC = oVar.c(i5);
                if (n.I(strC, "Date")) {
                    String strA = oVar.a("Date");
                    Date date = null;
                    if (strA != null) {
                        J3.b bVar = p7.a.f16154a;
                        if (strA.length() != 0) {
                            ParsePosition parsePosition = new ParsePosition(0);
                            Date date2 = ((DateFormat) p7.a.f16154a.get()).parse(strA, parsePosition);
                            if (parsePosition.getIndex() == strA.length()) {
                                date = date2;
                            } else {
                                String[] strArr = p7.a.f16155b;
                                synchronized (strArr) {
                                    try {
                                        int length = strArr.length;
                                        int i8 = 0;
                                        while (true) {
                                            if (i8 >= length) {
                                                break;
                                            }
                                            DateFormat[] dateFormatArr = p7.a.f16156c;
                                            DateFormat simpleDateFormat = dateFormatArr[i8];
                                            if (simpleDateFormat == null) {
                                                simpleDateFormat = new SimpleDateFormat(p7.a.f16155b[i8], Locale.US);
                                                simpleDateFormat.setTimeZone(l7.b.f14416e);
                                                dateFormatArr[i8] = simpleDateFormat;
                                            }
                                            parsePosition.setIndex(0);
                                            Date date3 = simpleDateFormat.parse(strA, parsePosition);
                                            if (parsePosition.getIndex() != 0) {
                                                date = date3;
                                                break;
                                            }
                                            i8++;
                                        }
                                    } catch (Throwable th) {
                                        throw th;
                                    }
                                }
                            }
                        }
                    }
                    this.f15640c = date;
                    this.f15641d = oVar.g(i5);
                } else if (n.I(strC, "Expires")) {
                    this.f15644g = oVar.b("Expires");
                } else if (n.I(strC, "Last-Modified")) {
                    this.f15642e = oVar.b("Last-Modified");
                    this.f15643f = oVar.g(i5);
                } else if (n.I(strC, "ETag")) {
                    this.f15646j = oVar.g(i5);
                } else if (n.I(strC, "Age")) {
                    String strG = oVar.g(i5);
                    Bitmap.Config[] configArr = u2.f.f17441a;
                    Long lF = m.F(strG);
                    if (lF != null) {
                        long jLongValue = lF.longValue();
                        i = jLongValue > 2147483647L ? Integer.MAX_VALUE : jLongValue < 0 ? 0 : (int) jLongValue;
                    } else {
                        i = -1;
                    }
                    this.f15647k = i;
                }
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x00d5  */
    /* JADX WARN: Type inference failed for: r5v1, types: [A6.e, java.lang.Object] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C1338d a() {
        C1336b c1336b;
        long jMax;
        Date date;
        String str;
        String string;
        long time;
        String str2;
        int i;
        y yVar = this.f15638a;
        C1336b c1336b2 = this.f15639b;
        if (c1336b2 == null) {
            return new C1338d(yVar, null);
        }
        q qVar = yVar.f14202a;
        if (qVar.f14129j && !c1336b2.f15636e) {
            return new C1338d(yVar, null);
        }
        ?? r52 = c1336b2.f15632a;
        C1111c c1111c = (C1111c) r52.getValue();
        if (yVar.a().f14047b || ((C1111c) r52.getValue()).f14047b || g.a(c1336b2.f15637f.a("Vary"), "*")) {
            return new C1338d(yVar, null);
        }
        C1111c c1111cA = yVar.a();
        if (!c1111cA.f14046a) {
            o oVar = yVar.f14204c;
            if (oVar.a("If-Modified-Since") == null && oVar.a("If-None-Match") == null) {
                long time2 = this.i;
                Date date2 = this.f15640c;
                if (date2 != null) {
                    c1336b = c1336b2;
                    jMax = Math.max(0L, time2 - date2.getTime());
                } else {
                    c1336b = c1336b2;
                    jMax = 0;
                }
                int i5 = this.f15647k;
                long millis = 0;
                if (i5 != -1) {
                    date = date2;
                    str = "If-Modified-Since";
                    jMax = Math.max(jMax, TimeUnit.SECONDS.toMillis(i5));
                } else {
                    date = date2;
                    str = "If-Modified-Since";
                }
                long time3 = this.f15645h;
                long jLongValue = jMax + (time2 - time3) + (((Number) u2.n.f17464a.a()).longValue() - time2);
                int i8 = ((C1111c) r52.getValue()).f14048c;
                Date date3 = this.f15642e;
                if (i8 != -1) {
                    time = TimeUnit.SECONDS.toMillis(i8);
                } else {
                    Date date4 = this.f15644g;
                    if (date4 != null) {
                        if (date != null) {
                            time2 = date.getTime();
                        }
                        time = date4.getTime() - time2;
                        if (time <= 0) {
                            time = 0;
                        }
                    } else if (date3 != null) {
                        ArrayList arrayList = qVar.f14127g;
                        if (arrayList == null) {
                            string = null;
                        } else {
                            StringBuilder sb = new StringBuilder();
                            l.h(arrayList, sb);
                            string = sb.toString();
                        }
                        if (string == null) {
                            if (date != null) {
                                time3 = date.getTime();
                            }
                            long time4 = time3 - date3.getTime();
                            if (time4 > 0) {
                                time = time4 / ((long) 10);
                            }
                        }
                    }
                }
                int i9 = c1111cA.f14048c;
                if (i9 != -1) {
                    time = Math.min(time, TimeUnit.SECONDS.toMillis(i9));
                }
                int i10 = c1111cA.i;
                long millis2 = i10 != -1 ? TimeUnit.SECONDS.toMillis(i10) : 0L;
                if (!c1111c.f14052g && (i = c1111cA.f14053h) != -1) {
                    millis = TimeUnit.SECONDS.toMillis(i);
                }
                if (!c1111c.f14046a && jLongValue + millis2 < time + millis) {
                    return new C1338d(null, c1336b);
                }
                C1336b c1336b3 = c1336b;
                String str3 = this.f15646j;
                if (str3 != null) {
                    str2 = "If-None-Match";
                } else {
                    if (date3 != null) {
                        str3 = this.f15643f;
                        g.b(str3);
                    } else {
                        if (date == null) {
                            return new C1338d(yVar, null);
                        }
                        str3 = this.f15641d;
                        g.b(str3);
                    }
                    str2 = str;
                }
                K2.e eVarB = yVar.b();
                eVarB.p(str2, str3);
                return new C1338d(eVarB.q(), c1336b3);
            }
        }
        return new C1338d(yVar, null);
    }
}
