package R5;

import a5.C0405d;
import android.app.Application;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.data.model.preference.GeneralPreference;
import com.martsnew.domain.model.Episode;
import com.martsnew.domain.model.EpisodeSource;
import com.martsnew.domain.model.Movie;
import com.martsnew.domain.model.Season;
import com.martsnew.domain.model.StreamUrl;
import com.martsnew.tv.R;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import k5.C1103c;
import l5.EnumC1136e;
import l5.EnumC1138g;
import o5.C1363b;
import o5.C1369h;
import o5.C1374m;
import p5.C1432b;
import p5.C1433c;
import q5.C1468e;
import y5.C1763h;

/* JADX INFO: loaded from: classes.dex */
public final class P extends y5.k {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final o5.q f6124d;

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final p5.j f6127g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final o5.s f6128h;
    public final C1363b i;

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final Application f6131l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final c7.K f6132m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public List f6133n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final ArrayList f6134o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public Long f6135p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public Episode f6136q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public Object f6137r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public EpisodeSource f6138s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public StreamUrl f6139t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final ArrayList f6140u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public EnumC1136e f6141v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public long f6142w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final A6.l f6143x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public Movie f6144y;

    public P(o5.q qVar, C1374m c1374m, C1433c c1433c, p5.j jVar, o5.s sVar, C1363b c1363b, C1468e c1468e, C1369h c1369h, Application application, p5.g gVar, C1432b c1432b) {
        P6.g.e(qVar, "getListEpisodeUseCase");
        P6.g.e(c1374m, "getEpisodeDetailUseCase");
        P6.g.e(c1433c, "getGeneralSettings");
        P6.g.e(jVar, "saveGeneralSettings");
        P6.g.e(sVar, "getListSeasonUseCase");
        P6.g.e(c1363b, "addToHistoryUseCase");
        P6.g.e(c1468e, "loginUserCase");
        P6.g.e(c1369h, "continueWatchUseCase");
        P6.g.e(gVar, "netCacheUseCase");
        P6.g.e(c1432b, "fbLogUseCase");
        this.f6124d = qVar;
        this.f6125e = c1374m;
        this.f6126f = c1433c;
        this.f6127g = jVar;
        this.f6128h = sVar;
        this.i = c1363b;
        this.f6129j = c1468e;
        this.f6130k = c1369h;
        this.f6131l = application;
        this.f6132m = c7.H.b(new C1763h(z.f6199a));
        this.f6133n = new ArrayList();
        this.f6134o = new ArrayList();
        this.f6139t = new StreamUrl(0);
        this.f6140u = new ArrayList();
        this.f6141v = EnumC1136e.f14397q;
        this.f6142w = -1L;
        g6.o oVar = g6.o.f12958a;
        this.f6143x = new A6.l(oVar.R(), oVar.Q(), oVar.S());
        e(false, new v(gVar, this, null));
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object h(P p3, G6.c cVar) throws Throwable {
        N n8;
        p3.getClass();
        if (cVar instanceof N) {
            n8 = (N) cVar;
            int i = n8.f6115w;
            if ((i & Integer.MIN_VALUE) != 0) {
                n8.f6115w = i - Integer.MIN_VALUE;
            } else {
                n8 = new N(p3, cVar);
            }
        }
        Object obj = n8.f6113u;
        F6.a aVar = F6.a.f2580q;
        int i5 = n8.f6115w;
        if (i5 == 0) {
            C1.N(obj);
            y5.n nVar = new y5.n(R.string.msg_no_playable_sources);
            n8.f6112t = p3;
            n8.f6115w = 1;
            if (p3.g(nVar, n8) == aVar) {
                return aVar;
            }
        } else {
            if (i5 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            p3 = n8.f6112t;
            C1.N(obj);
        }
        c7.K k8 = p3.f6132m;
        C1763h c1763h = new C1763h(z.f6200b);
        k8.getClass();
        k8.g(null, c1763h);
        return A6.n.f457a;
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x00c4  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C1103c i() {
        Object objJ;
        C1433c c1433c = this.f6126f;
        c1433c.getClass();
        String strF = g6.o.f12958a.F();
        P6.d dVarA = P6.n.a(GeneralPreference.class);
        boolean zEquals = dVarA.equals(P6.n.a(Float.TYPE));
        C0405d c0405d = c1433c.f16130a;
        if (zEquals) {
            objJ = (GeneralPreference) Float.valueOf(c0405d.f7619a.getFloat(strF, 0.0f));
        } else if (dVarA.equals(P6.n.a(Integer.TYPE))) {
            objJ = (GeneralPreference) Integer.valueOf(c0405d.f7619a.getInt(strF, 0));
        } else if (dVarA.equals(P6.n.a(Long.TYPE))) {
            objJ = (GeneralPreference) Long.valueOf(c0405d.f7619a.getLong(strF, 0L));
        } else if (dVarA.equals(P6.n.a(String.class))) {
            Object string = c0405d.f7619a.getString(strF, "");
            if (string == null) {
                throw new NullPointerException("null cannot be cast to non-null type com.martsnew.data.model.preference.GeneralPreference");
            }
            objJ = (GeneralPreference) string;
        } else if (dVarA.equals(P6.n.a(Boolean.TYPE))) {
            objJ = (GeneralPreference) Boolean.valueOf(c0405d.f7619a.getBoolean(strF, false));
        } else {
            String string2 = c0405d.f7619a.getString(strF, "");
            if (string2 == null || string2.length() == 0) {
                objJ = null;
            } else {
                try {
                    objJ = c0405d.f7620b.a(GeneralPreference.class).a(string2);
                } catch (Throwable th) {
                    objJ = C1.j(th);
                }
                if (objJ instanceof A6.i) {
                }
            }
        }
        GeneralPreference generalPreference = (GeneralPreference) objJ;
        EnumC1136e enumC1136e = EnumC1136e.f14397q;
        EnumC1138g enumC1138g = EnumC1138g.f14406q;
        if (generalPreference == null) {
            return new C1103c(0, 0, 80, 2, enumC1138g, enumC1136e, 0, "");
        }
        int i = generalPreference.f10576e;
        Object obj = enumC1138g;
        if (i >= 0) {
            H6.b bVar = EnumC1138g.f14408s;
            obj = enumC1138g;
            if (i < bVar.a()) {
                obj = bVar.get(i);
            }
        }
        EnumC1138g enumC1138g2 = (EnumC1138g) obj;
        int i5 = generalPreference.f10577f;
        Object obj2 = enumC1136e;
        if (i5 >= 0) {
            H6.b bVar2 = EnumC1136e.f14403w;
            obj2 = enumC1136e;
            if (i5 < bVar2.a()) {
                obj2 = bVar2.get(i5);
            }
        }
        return new C1103c(generalPreference.f10572a, generalPreference.f10573b, generalPreference.f10574c, generalPreference.f10575d, enumC1138g2, (EnumC1136e) obj2, generalPreference.f10578g, generalPreference.f10579h);
    }

    public final void j(Episode episode, Boolean bool) {
        P6.g.e(episode, "episode");
        e(false, new I(this, episode, bool, null));
    }

    public final void k() {
        int iNextIndex;
        ArrayList arrayList = this.f6140u;
        if (arrayList.isEmpty()) {
            return;
        }
        ListIterator listIterator = arrayList.listIterator(arrayList.size());
        while (true) {
            if (!listIterator.hasPrevious()) {
                iNextIndex = -1;
                break;
            }
            long j8 = ((Season) listIterator.previous()).f11079q;
            Long l8 = this.f6135p;
            if (l8 != null && j8 == l8.longValue()) {
                iNextIndex = listIterator.nextIndex();
                break;
            }
        }
        if (iNextIndex < 0 || iNextIndex > B6.l.V(arrayList)) {
            List list = ((Season) arrayList.get(0)).f11084v;
            if (list.isEmpty()) {
                e(false, new K(this, null));
                return;
            } else {
                j((Episode) B6.k.h0(list), Boolean.TRUE);
                return;
            }
        }
        Season season = (Season) arrayList.get(iNextIndex);
        List list2 = season.f11084v;
        Episode episode = this.f6136q;
        P6.g.e(list2, "<this>");
        int iIndexOf = list2.indexOf(episode);
        List list3 = season.f11084v;
        if (iIndexOf < B6.l.V(list3)) {
            j((Episode) list3.get(iIndexOf + 1), Boolean.TRUE);
            return;
        }
        if (iNextIndex >= B6.l.V(arrayList)) {
            e(false, new M(this, null));
            return;
        }
        List list4 = ((Season) arrayList.get(iNextIndex + 1)).f11084v;
        if (list4.isEmpty()) {
            e(false, new L(this, null));
        } else {
            j((Episode) B6.k.h0(list4), Boolean.TRUE);
        }
    }
}
