package defpackage;

import androidx.media3.exoplayer.rtsp.RtspHeaders;
import defpackage.h14;
import defpackage.vy6;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0016\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0005\u001a\u00020\u0004*\u000e\u0012\u0004\u0012\u00020\u0001\u0012\u0004\u0012\u00020\u00020\u00002\u0006\u0010\u0003\u001a\u00020\u0001H\n¢\u0006\u0004\b\u0005\u0010\u0006"}, d2 = {"Lj77;", "", "Lfd4;", "content", "Le6a;", "<anonymous>", "(Lj77;Ljava/lang/Object;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "io.ktor.client.plugins.cache.HttpCache$Companion$install$1", f = "HttpCache.kt", i = {1}, l = {160, 164, 170, 179, 184}, m = "invokeSuspend", n = {"$this$intercept"}, s = {"L$0"})
@vx8
final class i94 extends SuspendLambda implements ir3<j77<Object, fd4>, Object, Continuation<? super e6a>, Object> {
    public int a;
    public /* synthetic */ j77 b;
    public /* synthetic */ Object c;
    public final /* synthetic */ k94 d;
    public final /* synthetic */ ta4 e;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public i94(k94 k94Var, ta4 ta4Var, Continuation continuation) {
        super(3, continuation);
        this.d = k94Var;
        this.e = ta4Var;
    }

    @Override // defpackage.ir3
    public final Object invoke(Object obj, Object obj2, Object obj3) {
        i94 i94Var = new i94(this.d, this.e, (Continuation) obj3);
        i94Var.b = (j77) obj;
        i94Var.c = obj2;
        return i94Var.invokeSuspend(e6a.a);
    }

    /* JADX WARN: Code restructure failed: missing block: B:46:0x012b, code lost:
    
        if (r2 == r1) goto L128;
     */
    /* JADX WARN: Removed duplicated region for block: B:108:0x02e2  */
    /* JADX WARN: Removed duplicated region for block: B:111:0x02ef  */
    /* JADX WARN: Removed duplicated region for block: B:112:0x0308  */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        j77 j77Var;
        Object objB;
        e6a e6aVar;
        List list;
        Object next;
        Integer numValueOf;
        long j;
        int i;
        Object next2;
        int iIntValue;
        wea weaVar;
        String str;
        String str2;
        String str3;
        ck1 ck1Var = ck1.a;
        int i2 = this.a;
        e6a e6aVar2 = e6a.a;
        if (i2 == 0) {
            s38.b(obj);
            j77Var = this.b;
            Object obj2 = this.c;
            if (obj2 instanceof vy6.c) {
                Object obj3 = j77Var.a;
                if (cr4.b(((fd4) obj3).b, wc4.b)) {
                    fd4 fd4Var = (fd4) obj3;
                    b4a b4aVarD = fd4Var.a.d();
                    jh5 jh5Var = w94.a;
                    if (b4aVarD.a.equals("http") || b4aVarD.a.equals("https")) {
                        k94 k94Var = this.d;
                        k94Var.getClass();
                        this.b = j77Var;
                        this.a = 2;
                        objB = k94.b(k94Var, fd4Var, (vy6) obj2, this);
                        if (objB != ck1Var) {
                        }
                        return ck1Var;
                    }
                }
            }
            return e6aVar2;
        }
        if (i2 == 1) {
            s38.b(obj);
            return e6aVar2;
        }
        if (i2 != 2) {
            if (i2 == 3) {
                s38.b(obj);
                return e6aVar2;
            }
            if (i2 == 4) {
                s38.b(obj);
                return e6aVar2;
            }
            if (i2 != 5) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            return e6aVar2;
        }
        j77Var = this.b;
        s38.b(obj);
        objB = obj;
        er0 er0Var = (er0) objB;
        ta4 ta4Var = this.e;
        if (er0Var == null) {
            jh5 jh5Var2 = w94.a;
            if (rh5.a(jh5Var2)) {
                jh5Var2.h("No cached response for " + ((fd4) j77Var.a).a + " found");
            }
            i14 i14Var = ((fd4) j77Var.a).c;
            List list2 = qc4.a;
            if (oc4.a(i14Var.j(RtspHeaders.CACHE_CONTROL)).contains(sq0.d)) {
                if (jh5Var2.d()) {
                    jh5Var2.h("No cache found and \"only-if-cached\" set for " + ((fd4) j77Var.a).a);
                }
                dx dxVar = k94.e;
                this.b = null;
                this.a = 3;
                j77Var.d();
                gd4 gd4VarA = ((fd4) j77Var.a).a();
                pe4 pe4Var = pe4.r;
                ns3 ns3VarB = ys1.b(null);
                h14.a.getClass();
                Object objH = j77Var.h(new ua4(ta4Var, gd4VarA, new ud4(pe4Var, ns3VarB, h14.a.a(), zc4.f, bm0.a(new byte[0]), gd4VarA.e)), this);
                if (objH != ck1.a) {
                    objH = e6aVar2;
                }
            }
            return e6aVar2;
        }
        h14 h14Var = er0Var.g;
        ns3 ns3Var = er0Var.f;
        Object obj4 = j77Var.a;
        fd4 fd4Var2 = (fd4) obj4;
        cr4.g(ns3Var, "cacheExpires");
        cr4.g(h14Var, "responseHeaders");
        cr4.g(fd4Var2, "request");
        v3a v3aVar = fd4Var2.a;
        i14 i14Var2 = fd4Var2.c;
        List list3 = qc4.a;
        List listD = h14Var.d(RtspHeaders.CACHE_CONTROL);
        List listA = oc4.a(listD != null ? y41.ai(listD, ",", null, null, null, 62) : null);
        List listD2 = i14Var2.d(RtspHeaders.CACHE_CONTROL);
        List listA2 = oc4.a(listD2 != null ? y41.ai(listD2, ",", null, null, null, 62) : null);
        if (listA2.contains(sq0.b)) {
            w94.a.h("\"no-cache\" is set for " + v3aVar + ", should validate cached response");
            weaVar = wea.a;
            e6aVar = e6aVar2;
        } else {
            List list4 = listA2;
            Iterator it = list4.iterator();
            while (true) {
                if (!it.hasNext()) {
                    e6aVar = e6aVar2;
                    list = list4;
                    next = null;
                    break;
                }
                next = it.next();
                e6aVar = e6aVar2;
                list = list4;
                if (n89.ar(((b14) next).a, "max-age=", false)) {
                    break;
                }
                e6aVar2 = e6aVar;
                list4 = list;
            }
            b14 b14Var = (b14) next;
            if (b14Var == null || (str2 = b14Var.a) == null || (str3 = (String) n89.ao(str2, new String[]{"="}, 6).get(1)) == null) {
                numValueOf = null;
            } else {
                Integer numBe = n89.be(str3);
                numValueOf = Integer.valueOf(numBe != null ? numBe.intValue() : 0);
            }
            if (numValueOf != null && numValueOf.intValue() == 0) {
                w94.a.h("\"max-age\" is not set for " + v3aVar + ", should validate cached response");
                weaVar = wea.a;
            } else if (listA.contains(sq0.b)) {
                w94.a.h("\"no-cache\" is set for " + v3aVar + ", should validate cached response");
                weaVar = wea.a;
            } else {
                long jCurrentTimeMillis = ns3Var.k - System.currentTimeMillis();
                long j2 = 0;
                if (jCurrentTimeMillis > 0) {
                    w94.a.h("Cached response is valid for " + v3aVar + ", should not validate");
                    weaVar = wea.b;
                } else if (listA.contains(sq0.e)) {
                    w94.a.h("\"must-revalidate\" is set for " + v3aVar + ", should validate cached response");
                    weaVar = wea.a;
                } else {
                    Iterator it2 = list.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            j = j2;
                            i = 0;
                            next2 = null;
                            break;
                        }
                        next2 = it2.next();
                        j = j2;
                        i = 0;
                        if (n89.ar(((b14) next2).a, "max-stale=", false)) {
                            break;
                        }
                        j2 = j;
                    }
                    b14 b14Var2 = (b14) next2;
                    if (b14Var2 == null || (str = b14Var2.a) == null) {
                        iIntValue = i;
                        if ((((long) iIntValue) * 1000) + jCurrentTimeMillis <= j) {
                            w94.a.h("Cached response is stale for " + v3aVar + " but less than max-stale, should warn");
                            weaVar = wea.c;
                        } else {
                            w94.a.h("Cached response is stale for " + v3aVar + ", should validate cached response");
                            weaVar = wea.a;
                        }
                    } else {
                        String strSubstring = str.substring(10);
                        cr4.f(strSubstring, "substring(...)");
                        Integer numBe2 = n89.be(strSubstring);
                        if (numBe2 != null) {
                            iIntValue = numBe2.intValue();
                        }
                        if ((((long) iIntValue) * 1000) + jCurrentTimeMillis <= j) {
                        }
                    }
                }
            }
        }
        if (weaVar == wea.b) {
            fd4 fd4Var3 = (fd4) obj4;
            ua4 a = ja4.a(er0Var, ta4Var, new u08(fd4Var3.a()), fd4Var3.e).getA();
            dx dxVar2 = k94.e;
            this.b = null;
            this.a = 4;
            j77Var.d();
            ta4Var.l.a(k94.f, a.g());
            Object objH2 = j77Var.h(a, this);
            if (objH2 != ck1Var) {
                objH2 = e6aVar;
            }
            if (objH2 != ck1Var) {
                return e6aVar;
            }
        } else {
            if (weaVar != wea.c) {
                List list5 = qc4.a;
                String strE = h14Var.e("ETag");
                if (strE != null) {
                    jh5 jh5Var3 = w94.a;
                    if (rh5.a(jh5Var3)) {
                        StringBuilder sbS = vw2.s("Adding If-None-Match=", strE, " for ");
                        sbS.append(((fd4) obj4).a);
                        jh5Var3.h(sbS.toString());
                    }
                    dea.a((tc4) obj4, "If-None-Match", strE);
                }
                String strE2 = h14Var.e("Last-Modified");
                if (strE2 == null) {
                    return e6aVar;
                }
                jh5 jh5Var4 = w94.a;
                if (rh5.a(jh5Var4)) {
                    StringBuilder sbS2 = vw2.s("Adding If-Modified-Since=", strE2, " for ");
                    sbS2.append(((fd4) obj4).a);
                    jh5Var4.h(sbS2.toString());
                }
                dea.a((tc4) obj4, "If-Modified-Since", strE2);
                return e6aVar;
            }
            dx dxVar3 = k94.e;
            fd4 fd4Var4 = (fd4) obj4;
            fx4 fx4Var = fd4Var4.e;
            this.b = null;
            this.a = 5;
            gd4 gd4VarA2 = fd4Var4.a();
            pe4 pe4Var2 = er0Var.b;
            ns3 ns3Var2 = er0Var.c;
            h14.a aVar = h14.a;
            i14 i14Var3 = new i14();
            i14Var3.h(h14Var);
            List list6 = qc4.a;
            i14Var3.g("Warning", "110");
            ua4 ua4Var = new ua4(ta4Var, gd4VarA2, new ud4(pe4Var2, ns3Var2, i14Var3.m(), er0Var.e, bm0.a(er0Var.i), fx4Var));
            j77Var.d();
            ta4Var.l.a(k94.f, ua4Var.g());
            Object objH3 = j77Var.h(ua4Var, this);
            if (objH3 != ck1Var) {
                objH3 = e6aVar;
            }
            if (objH3 != ck1Var) {
                return e6aVar;
            }
        }
        return ck1Var;
    }
}
