package V2;

import a3.C0982v;
import android.os.SystemClock;
import androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection;
import e3.AbstractC1964a;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import w4.C3137A;

/* JADX INFO: renamed from: V2.f3, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0661f3 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final AtomicInteger f7764a = new AtomicInteger(0);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Object f7765b = new Object();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Y4.c0 f7766c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final Y4.c0 f7767d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static J4.a f7768e;

    static {
        Y4.c0 c0VarC = Y4.O.c(new C0636a3());
        f7766c = c0VarC;
        f7767d = c0VarC;
    }

    public static C0656e3 a() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        TimeUnit timeUnit = TimeUnit.SECONDS;
        builder.c(8L);
        builder.d(12L);
        builder.e(8L);
        TimeUnit timeUnit2 = TimeUnit.MINUTES;
        builder.f22095b = new ConnectionPool(32, 5L);
        AbstractC1964a.b(builder);
        return new C0656e3(new OkHttpClient(builder), 0);
    }

    public static void b(Integer num, Integer num2, String imdbId, String type, String str, boolean z6) {
        Integer numValueOf;
        Integer numValueOf2;
        String string;
        kotlin.jvm.internal.o.h(imdbId, "imdbId");
        kotlin.jvm.internal.o.h(type, "type");
        String string2 = S4.p.o1(imdbId).toString();
        String lowerCase = S4.p.o1(type).toString().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        if (string2.length() == 0 || lowerCase.length() == 0) {
            return;
        }
        String str2 = null;
        boolean z7 = true;
        if (lowerCase.equals("tv")) {
            int iIntValue = num != null ? num.intValue() : 1;
            if (iIntValue < 1) {
                iIntValue = 1;
            }
            numValueOf = Integer.valueOf(iIntValue);
        } else {
            numValueOf = null;
        }
        if (lowerCase.equals("tv")) {
            int iIntValue2 = num2 != null ? num2.intValue() : 1;
            if (iIntValue2 < 1) {
                iIntValue2 = 1;
            }
            numValueOf2 = Integer.valueOf(iIntValue2);
        } else {
            numValueOf2 = null;
        }
        String str3 = (str == null || (string = S4.p.o1(str).toString()) == null || string.length() <= 0) ? null : string;
        if (c() && (kotlin.jvm.internal.o.c(((Y4.c0) z3.f8213b.f8871a).getValue(), "kids") || ((n3) ((Y4.c0) u3.f8112c.f8871a).getValue()).f7974d.f7379b)) {
            str2 = str3;
        }
        C0636a3 c0636a3 = (C0636a3) f7766c.getValue();
        boolean z8 = kotlin.jvm.internal.o.c(c0636a3.f7682a, string2) && kotlin.jvm.internal.o.c(c0636a3.f7683b, lowerCase) && kotlin.jvm.internal.o.c(c0636a3.f7684c, numValueOf) && kotlin.jvm.internal.o.c(c0636a3.f7685d, numValueOf2) && c0636a3.f7686e == z6 && kotlin.jvm.internal.o.c(c0636a3.f7687f, str2);
        if (c0636a3.f7691j.isEmpty() && c0636a3.f7690i <= 0) {
            z7 = false;
        }
        if (z8 && (c0636a3.f7689h || z7)) {
            return;
        }
        d(numValueOf, numValueOf2, string2, lowerCase, str3, z6);
    }

    public static boolean c() {
        String lowerCase = S4.p.o1(((n3) ((Y4.c0) u3.f8112c.f8871a).getValue()).f7971a.f7887b).toString().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        return lowerCase.equals("en") || S4.w.A0(lowerCase, "en-", false);
    }

    public static void d(Integer num, Integer num2, String imdbId, String str, String str2, boolean z6) {
        Integer numValueOf;
        Integer numValueOf2;
        String string;
        kotlin.jvm.internal.o.h(imdbId, "imdbId");
        String string2 = S4.p.o1(imdbId).toString();
        if (string2.length() == 0) {
            return;
        }
        String lowerCase = S4.p.o1(str).toString().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        if (lowerCase.length() == 0) {
            return;
        }
        if (lowerCase.equals("tv")) {
            int iIntValue = num != null ? num.intValue() : 1;
            if (iIntValue < 1) {
                iIntValue = 1;
            }
            numValueOf = Integer.valueOf(iIntValue);
        } else {
            numValueOf = null;
        }
        if (lowerCase.equals("tv")) {
            int iIntValue2 = num2 != null ? num2.intValue() : 1;
            numValueOf2 = Integer.valueOf(iIntValue2 >= 1 ? iIntValue2 : 1);
        } else {
            numValueOf2 = null;
        }
        String str3 = (str2 == null || (string = S4.p.o1(str2).toString()) == null || string.length() <= 0) ? null : string;
        String str4 = (c() && (kotlin.jvm.internal.o.c(((Y4.c0) z3.f8213b.f8871a).getValue(), "kids") || ((n3) ((Y4.c0) u3.f8112c.f8871a).getValue()).f7974d.f7379b)) ? str3 : null;
        final int iIncrementAndGet = f7764a.incrementAndGet();
        J4.a aVar = f7768e;
        if (aVar != null) {
            aVar.invoke();
        }
        f7768e = null;
        synchronized (f7765b) {
            AbstractC0666g3.f7783a.clear();
        }
        Y4.c0 c0Var = f7766c;
        C0636a3 c0636a3 = new C0636a3(string2, lowerCase, numValueOf, numValueOf2, z6, str4, str3, true, 0, x4.y.f26065a, SystemClock.elapsedRealtime());
        c0Var.getClass();
        c0Var.k(null, c0636a3);
        C0656e3 c0656e3A = a();
        Set setB = ((n3) ((Y4.c0) u3.f8112c.f8871a).getValue()).f7976f.b();
        f7768e = N2.q.l(string2, lowerCase, new N2.u(numValueOf, numValueOf2, lowerCase, str4, str3, z6), setB, C3.b(setB), new J4.g() { // from class: V2.b3
            @Override // J4.g
            public final Object invoke(Object obj, Object obj2, Object obj3, Object obj4) {
                int i6 = iIncrementAndGet;
                List links = (List) obj4;
                kotlin.jvm.internal.o.h((T2.g) obj, "<unused var>");
                kotlin.jvm.internal.o.h((T2.c) obj2, "<unused var>");
                kotlin.jvm.internal.o.h((String) obj3, "<unused var>");
                kotlin.jvm.internal.o.h(links, "links");
                if (!links.isEmpty() && i6 == AbstractC0661f3.f7764a.get()) {
                    J2 j22 = ((n3) ((Y4.c0) u3.f8112c.f8871a).getValue()).f7974d;
                    synchronized (AbstractC0661f3.f7765b) {
                        Y4.c0 c0Var2 = AbstractC0661f3.f7766c;
                        C0636a3 c0636a32 = (C0636a3) c0Var2.getValue();
                        List listB = AbstractC0666g3.b(c0636a32.f7691j, links, new C0982v(j22.f7380c, j22.f7381d, j22.f7387j, j22.f7395s, j22.f7384g, j22.f7386i, j22.f7382e, j22.f7383f, j22.f7391o, j22.f7392p, j22.f7390n, j22.f7385h || j22.f7393q, j22.f7394r, j22.l, j22.f7389m, j22.f7388k, Double.valueOf(j22.f7378a), c0636a32.f7688g));
                        C0636a3 c0636a3A = C0636a3.a(c0636a32, listB.size(), listB, AdaptiveTrackSelection.DEFAULT_MAX_WIDTH_TO_DISCARD);
                        c0Var2.getClass();
                        c0Var2.k(null, c0636a3A);
                    }
                }
                return C3137A.f25453a;
            }
        }, new C0646c3(iIncrementAndGet, 0), c0656e3A);
    }
}
