package j5;

import com.martsnew.data.model.response.ContinueWatchResponse;
import com.martsnew.data.model.response.EpisodeResponse;
import com.martsnew.data.model.response.ListEpisodeResponse;
import com.martsnew.domain.model.Episode;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: renamed from: j5.j, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1079j implements p {
    public static k5.j b(ListEpisodeResponse listEpisodeResponse) {
        ContinueWatchResponse continueWatchResponse;
        long j8;
        boolean z8;
        String str;
        int i;
        long j9;
        String str2;
        String str3;
        Double d8;
        Long l8;
        Object next;
        P6.g.e(listEpisodeResponse, "dto");
        List list = listEpisodeResponse.f10831b;
        ContinueWatchResponse continueWatchResponse2 = list != null ? (ContinueWatchResponse) B6.k.o0(list) : null;
        Iterable iterable = listEpisodeResponse.f10830a;
        if (iterable == null) {
            iterable = B6.t.f1032q;
        }
        ArrayList arrayList = new ArrayList(B6.m.a0(iterable));
        Iterator it = iterable.iterator();
        while (it.hasNext()) {
            EpisodeResponse episodeResponse = (EpisodeResponse) it.next();
            if (list != null) {
                Iterator it2 = list.iterator();
                while (true) {
                    if (!it2.hasNext()) {
                        next = null;
                        break;
                    }
                    next = it2.next();
                    Long l9 = ((ContinueWatchResponse) next).f10695e;
                    long j10 = episodeResponse.f10753a;
                    if (l9 != null && l9.longValue() == j10) {
                        break;
                    }
                }
                continueWatchResponse = (ContinueWatchResponse) next;
            } else {
                continueWatchResponse = null;
            }
            long j11 = episodeResponse.f10753a;
            Long l10 = episodeResponse.f10754b;
            long jLongValue = l10 != null ? l10.longValue() : -1L;
            String str4 = episodeResponse.f10755c;
            if (str4 == null) {
                str4 = "";
            }
            String strK = X6.n.K(str4, "{width}x{height}", "500x281");
            Long l11 = episodeResponse.f10756d;
            long jLongValue2 = l11 != null ? l11.longValue() : -1L;
            String str5 = episodeResponse.f10757e;
            String str6 = str5 == null ? "" : str5;
            long jLongValue3 = 0;
            Long l12 = episodeResponse.f10758f;
            long jLongValue4 = l12 != null ? l12.longValue() : 0L;
            String str7 = episodeResponse.f10759g;
            String str8 = str7 != null ? str7 : "";
            Integer num = episodeResponse.f10760h;
            int iIntValue = num != null ? num.intValue() : 0;
            Iterator it3 = it;
            if (continueWatchResponse != null && (l8 = continueWatchResponse.f10698h) != null) {
                jLongValue3 = l8.longValue();
            }
            long j12 = jLongValue3;
            int iS = (continueWatchResponse == null || (d8 = continueWatchResponse.i) == null) ? 0 : android.support.v4.media.session.a.s(d8.doubleValue());
            if (continueWatchResponse2 != null) {
                Long l13 = continueWatchResponse2.f10695e;
                if (l13 == null) {
                    str3 = strK;
                } else {
                    str3 = strK;
                    if (l13.longValue() == episodeResponse.f10753a) {
                        z8 = true;
                        j8 = jLongValue4;
                    }
                    str = str8;
                    i = iIntValue;
                    j9 = jLongValue;
                    str2 = str3;
                }
                j8 = jLongValue4;
                z8 = false;
                str = str8;
                i = iIntValue;
                j9 = jLongValue;
                str2 = str3;
            } else {
                j8 = jLongValue4;
                z8 = false;
                str = str8;
                i = iIntValue;
                j9 = jLongValue;
                str2 = strK;
            }
            arrayList.add(new Episode(j11, j9, str2, jLongValue2, str6, j8, str, i, j12, iS, z8));
            it = it3;
        }
        return new k5.j(arrayList);
    }

    @Override // j5.p
    public final /* bridge */ /* synthetic */ Object a(Object obj) {
        return b((ListEpisodeResponse) obj);
    }
}
