package com.strmr.ps.ui.deeplink;

import androidx.media3.container.NalUnitUtil;
import androidx.media3.extractor.AacUtil;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.tmdb.TMDBFindResponse;
import com.strmr.ps.data.model.tmdb.TMDBFindResult;
import com.strmr.ps.data.remote.RateLimiter;
import com.strmr.ps.data.remote.api.TMDBApiService;
import com.strmr.ps.ui.deeplink.DeepLinkViewModel;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.ig6;
import defpackage.n41;
import defpackage.n89;
import defpackage.s38;
import defpackage.y41;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.deeplink.DeepLinkViewModel$resolve$1", f = "DeepLinkViewModel.kt", i = {0, 1}, l = {AacUtil.AUDIO_OBJECT_TYPE_AAC_XHE, 43}, m = "invokeSuspend", n = {"normalizedId", "normalizedId"}, s = {"L$0", "L$0"})
final class f extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public String a;
    public int b;
    public final /* synthetic */ DeepLinkViewModel c;
    public final /* synthetic */ String d;
    public final /* synthetic */ String e;

    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public /* synthetic */ class a {
        public static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[ContentItem.ItemType.values().length];
            try {
                iArr[ContentItem.ItemType.MOVIE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[ContentItem.ItemType.TV_SHOW.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            a = iArr;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public f(DeepLinkViewModel deepLinkViewModel, String str, String str2, Continuation continuation) {
        super(2, continuation);
        this.c = deepLinkViewModel;
        this.d = str;
        this.e = str2;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new f(this.c, this.d, this.e, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((f) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Code restructure failed: missing block: B:40:0x009c, code lost:
    
        if (r0 == r7) goto L41;
     */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00bc  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x0139 A[Catch: Exception -> 0x001e, TryCatch #0 {Exception -> 0x001e, blocks: (B:7:0x0017, B:42:0x009f, B:44:0x00ab, B:46:0x00b0, B:70:0x0119, B:72:0x011d, B:74:0x0123, B:76:0x012b, B:108:0x0193, B:110:0x01a0, B:80:0x0139, B:82:0x013d, B:84:0x0143, B:86:0x014b, B:90:0x0159, B:92:0x015f, B:94:0x0167, B:98:0x0174, B:100:0x017a, B:102:0x0182, B:50:0x00be, B:52:0x00c4, B:54:0x00cc, B:55:0x00d5, B:57:0x00db, B:59:0x00e3, B:60:0x00ec, B:62:0x00f2, B:64:0x00fa, B:65:0x0103, B:67:0x0109, B:69:0x0111, B:45:0x00ae, B:14:0x002b, B:39:0x008b, B:17:0x0032, B:33:0x0063, B:35:0x007d, B:20:0x003d, B:22:0x0043, B:25:0x004e, B:26:0x0051, B:30:0x005b), top: B:114:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:90:0x0159 A[Catch: Exception -> 0x001e, TryCatch #0 {Exception -> 0x001e, blocks: (B:7:0x0017, B:42:0x009f, B:44:0x00ab, B:46:0x00b0, B:70:0x0119, B:72:0x011d, B:74:0x0123, B:76:0x012b, B:108:0x0193, B:110:0x01a0, B:80:0x0139, B:82:0x013d, B:84:0x0143, B:86:0x014b, B:90:0x0159, B:92:0x015f, B:94:0x0167, B:98:0x0174, B:100:0x017a, B:102:0x0182, B:50:0x00be, B:52:0x00c4, B:54:0x00cc, B:55:0x00d5, B:57:0x00db, B:59:0x00e3, B:60:0x00ec, B:62:0x00f2, B:64:0x00fa, B:65:0x0103, B:67:0x0109, B:69:0x0111, B:45:0x00ae, B:14:0x002b, B:39:0x008b, B:17:0x0032, B:33:0x0063, B:35:0x007d, B:20:0x003d, B:22:0x0043, B:25:0x004e, B:26:0x0051, B:30:0x005b), top: B:114:0x000f }] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        String strConcat;
        String str;
        String str2;
        Object objFindByExternalId$default;
        TMDBFindResult tMDBFindResult;
        Integer numBoxInt;
        TMDBFindResult tMDBFindResult2;
        TMDBFindResult tMDBFindResult3;
        TMDBFindResult tMDBFindResult4;
        TMDBFindResult tMDBFindResult5;
        TMDBFindResult tMDBFindResult6;
        TMDBFindResult tMDBFindResult7;
        TMDBFindResult tMDBFindResult8;
        String str3 = this.d;
        DeepLinkViewModel deepLinkViewModel = this.c;
        ig6 ig6Var = deepLinkViewModel.c;
        ck1 ck1Var = ck1.a;
        int i = this.b;
        e6a e6aVar = e6a.a;
        ContentItem.ItemType itemType = null;
        try {
            if (i == 0) {
                s38.b(obj);
                int i2 = 0;
                if (n89.ar(str3, TtmlNode.TAG_TT, false)) {
                    strConcat = str3;
                } else {
                    while (true) {
                        if (i2 >= str3.length()) {
                            int length = str3.length();
                            if (1 > length || length >= 11) {
                                break;
                            }
                            strConcat = TtmlNode.TAG_TT.concat(str3);
                        } else {
                            if (!Character.isDigit(str3.charAt(i2))) {
                                break;
                            }
                            i2++;
                        }
                    }
                    strConcat = null;
                }
                if (strConcat == null) {
                    ig6Var.setValue(new DeepLinkViewModel.a.C0111a("Invalid IMDB ID: " + str3));
                    return e6aVar;
                }
                RateLimiter rateLimiter = deepLinkViewModel.b;
                this.a = strConcat;
                this.b = 1;
                if (rateLimiter.a(this) == ck1Var) {
                    return ck1Var;
                }
                str = strConcat;
            } else {
                if (i != 1) {
                    if (i != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    String str4 = this.a;
                    s38.b(obj);
                    str2 = str4;
                    objFindByExternalId$default = obj;
                    TMDBFindResponse tMDBFindResponse = (TMDBFindResponse) objFindByExternalId$default;
                    ContentItem.ItemType itemType2 = this.e.equals(PlaybackProgress.TYPE_MOVIE) ? ContentItem.ItemType.MOVIE : ContentItem.ItemType.TV_SHOW;
                    int i3 = a.a[itemType2.ordinal()];
                    if (i3 == 1) {
                        List<TMDBFindResult> movieResults = tMDBFindResponse.getMovieResults();
                        if (movieResults == null || (tMDBFindResult2 = (TMDBFindResult) y41.ab(movieResults)) == null) {
                            List<TMDBFindResult> tvResults = tMDBFindResponse.getTvResults();
                            if (tvResults != null && (tMDBFindResult = (TMDBFindResult) y41.ab(tvResults)) != null) {
                                numBoxInt = Boxing.boxInt(tMDBFindResult.getId());
                            }
                        } else {
                            numBoxInt = Boxing.boxInt(tMDBFindResult2.getId());
                        }
                    } else if (i3 == 2) {
                        List<TMDBFindResult> tvResults2 = tMDBFindResponse.getTvResults();
                        if (tvResults2 == null || (tMDBFindResult8 = (TMDBFindResult) y41.ab(tvResults2)) == null) {
                            List<TMDBFindResult> movieResults2 = tMDBFindResponse.getMovieResults();
                            numBoxInt = (movieResults2 == null || (tMDBFindResult7 = (TMDBFindResult) y41.ab(movieResults2)) == null) ? null : Boxing.boxInt(tMDBFindResult7.getId());
                        } else {
                            numBoxInt = Boxing.boxInt(tMDBFindResult8.getId());
                        }
                    }
                    ContentItem.ItemType itemType3 = ContentItem.ItemType.MOVIE;
                    if (itemType2 != itemType3) {
                        ContentItem.ItemType itemType4 = ContentItem.ItemType.TV_SHOW;
                        if (itemType2 != itemType4) {
                            List<TMDBFindResult> movieResults3 = tMDBFindResponse.getMovieResults();
                            if (((movieResults3 == null || (tMDBFindResult4 = (TMDBFindResult) y41.ab(movieResults3)) == null) ? null : Boxing.boxInt(tMDBFindResult4.getId())) != null) {
                                itemType = itemType3;
                            } else {
                                List<TMDBFindResult> tvResults3 = tMDBFindResponse.getTvResults();
                                if (((tvResults3 == null || (tMDBFindResult3 = (TMDBFindResult) y41.ab(tvResults3)) == null) ? null : Boxing.boxInt(tMDBFindResult3.getId())) != null) {
                                    itemType = itemType4;
                                }
                            }
                        } else {
                            List<TMDBFindResult> tvResults4 = tMDBFindResponse.getTvResults();
                            if (((tvResults4 == null || (tMDBFindResult5 = (TMDBFindResult) y41.ab(tvResults4)) == null) ? null : Boxing.boxInt(tMDBFindResult5.getId())) != null) {
                                itemType = itemType4;
                            }
                        }
                    } else {
                        List<TMDBFindResult> movieResults4 = tMDBFindResponse.getMovieResults();
                        if (((movieResults4 == null || (tMDBFindResult6 = (TMDBFindResult) y41.ab(movieResults4)) == null) ? null : Boxing.boxInt(tMDBFindResult6.getId())) != null) {
                            itemType = itemType3;
                        }
                    }
                    if (numBoxInt != null && itemType != null) {
                        ig6Var.setValue(new DeepLinkViewModel.a.c(numBoxInt.intValue(), itemType, str2));
                        return e6aVar;
                    }
                    ig6Var.setValue(new DeepLinkViewModel.a.C0111a("Content not found for " + str2));
                    return e6aVar;
                }
                str = this.a;
                s38.b(obj);
            }
            TMDBApiService tMDBApiService = deepLinkViewModel.a;
            this.a = str;
            this.b = 2;
            str2 = str;
            objFindByExternalId$default = TMDBApiService.DefaultImpls.findByExternalId$default(tMDBApiService, str2, null, this, 2, null);
        } catch (Exception e) {
            ig6Var.setValue(new DeepLinkViewModel.a.C0111a(n41.n("Failed to resolve content: ", e.getMessage())));
            return e6aVar;
        }
    }
}
