package com.strmr.ps.domain;

import androidx.media3.common.C;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import androidx.media3.session.MediaUtils;
import com.strmr.ps.data.local.entity.TraktUserItem;
import com.strmr.ps.data.model.ContentItem;
import defpackage.ag8;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.n89;
import defpackage.s38;
import defpackage.vx8;
import defpackage.xf8;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import okhttp3.internal.http2.Http2Connection;

/* 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\u0004\u0018\u00010\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Lcom/strmr/ps/data/model/ContentItem;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.domain.ContentLoaderUseCase$enrichTraktItems$2$1$1", f = "ContentLoaderUseCase.kt", i = {0, 1, 2}, l = {1169, 1072, 1073}, m = "invokeSuspend", n = {"$this$withPermit$iv", "$this$withPermit$iv", "$this$withPermit$iv"}, s = {"L$0", "L$0", "L$0"})
@vx8
final class e extends SuspendLambda implements gr3<ak1, Continuation<? super ContentItem>, Object> {
    public xf8 a;
    public TraktUserItem b;
    public ContentLoaderUseCase c;
    public int d;
    public int e;
    public final /* synthetic */ ContentLoaderUseCase f;
    public final /* synthetic */ TraktUserItem i;
    public final /* synthetic */ int j;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public e(ContentLoaderUseCase contentLoaderUseCase, TraktUserItem traktUserItem, int i, Continuation continuation) {
        super(2, continuation);
        this.f = contentLoaderUseCase;
        this.i = traktUserItem;
        this.j = i;
    }

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

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

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00cb A[Catch: all -> 0x001e, TRY_ENTER, TryCatch #1 {all -> 0x001e, blocks: (B:8:0x0016, B:51:0x00cb, B:53:0x00d1, B:54:0x00d5, B:15:0x002d), top: B:60:0x000a }] */
    /* JADX WARN: Type inference failed for: r2v0, types: [int] */
    /* JADX WARN: Type inference failed for: r2v1 */
    /* JADX WARN: Type inference failed for: r2v11, types: [xf8] */
    /* JADX WARN: Type inference failed for: r2v2, types: [xf8] */
    /* JADX WARN: Type inference failed for: r2v6 */
    /* JADX WARN: Type inference failed for: r7v0, types: [xf8] */
    /* JADX WARN: Type inference failed for: r8v1 */
    /* JADX WARN: Type inference failed for: r8v10 */
    /* JADX WARN: Type inference failed for: r8v11 */
    /* JADX WARN: Type inference failed for: r8v12 */
    /* JADX WARN: Type inference failed for: r8v13 */
    /* JADX WARN: Type inference failed for: r8v14 */
    /* JADX WARN: Type inference failed for: r8v15 */
    /* JADX WARN: Type inference failed for: r8v16 */
    /* JADX WARN: Type inference failed for: r8v2, types: [xf8] */
    /* JADX WARN: Type inference failed for: r8v3 */
    /* JADX WARN: Type inference failed for: r8v4 */
    /* JADX WARN: Type inference failed for: r8v5 */
    /* JADX WARN: Type inference failed for: r8v6 */
    /* JADX WARN: Type inference failed for: r8v8 */
    /* JADX WARN: Type inference failed for: r8v9 */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        ?? r8;
        TraktUserItem traktUserItem;
        ContentLoaderUseCase contentLoaderUseCase;
        int i;
        ContentItem contentItem;
        Object objC;
        TraktUserItem traktUserItem2;
        Object objB;
        ?? r82;
        ContentItem contentItem2;
        ?? r83;
        ?? r84;
        ?? r85;
        ck1 ck1Var = ck1.a;
        ?? r2 = this.e;
        ContentItem contentItemCopy = null;
        try {
            try {
                if (r2 == 0) {
                    s38.b(obj);
                    ContentLoaderUseCase contentLoaderUseCase2 = this.f;
                    ?? r7 = contentLoaderUseCase2.n;
                    this.a = r7;
                    TraktUserItem traktUserItem3 = this.i;
                    this.b = traktUserItem3;
                    this.c = contentLoaderUseCase2;
                    int i2 = this.j;
                    this.d = i2;
                    this.e = 1;
                    if (((ag8) r7).b(this) != ck1Var) {
                        r8 = r7;
                        traktUserItem = traktUserItem3;
                        contentLoaderUseCase = contentLoaderUseCase2;
                        i = i2;
                    }
                    return ck1Var;
                }
                if (r2 != 1) {
                    if (r2 == 2) {
                        traktUserItem2 = this.b;
                        xf8 xf8Var = this.a;
                        s38.b(obj);
                        r82 = xf8Var;
                        objB = obj;
                        contentItem2 = (ContentItem) objB;
                        r84 = r82;
                        traktUserItem = traktUserItem2;
                        contentItem = contentItem2;
                        r83 = r84;
                        r2 = r83;
                        if (contentItem != null) {
                        }
                        r2.release();
                        return contentItemCopy;
                    }
                    if (r2 != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    traktUserItem2 = this.b;
                    xf8 xf8Var2 = this.a;
                    s38.b(obj);
                    r85 = xf8Var2;
                    objC = obj;
                    contentItem2 = (ContentItem) objC;
                    r84 = r85;
                    traktUserItem = traktUserItem2;
                    contentItem = contentItem2;
                    r83 = r84;
                    r2 = r83;
                    if (contentItem != null) {
                        Long listedAt = traktUserItem.getListedAt();
                        if (listedAt == null) {
                            listedAt = traktUserItem.getCollectedAt();
                        }
                        contentItemCopy = contentItem.copy(((-1179113) & 1) != 0 ? contentItem.id : 0, ((-1179113) & 2) != 0 ? contentItem.itemType : null, ((-1179113) & 4) != 0 ? contentItem.tmdbId : 0, ((-1179113) & 8) != 0 ? contentItem.imdbId : null, ((-1179113) & 16) != 0 ? contentItem.title : null, ((-1179113) & 32) != 0 ? contentItem.overview : null, ((-1179113) & 64) != 0 ? contentItem.posterUrl : null, ((-1179113) & 128) != 0 ? contentItem.backdropUrl : null, ((-1179113) & 256) != 0 ? contentItem.logoUrl : null, ((-1179113) & 512) != 0 ? contentItem.episodeStillUrl : null, ((-1179113) & 1024) != 0 ? contentItem.year : null, ((-1179113) & 2048) != 0 ? contentItem.rating : null, ((-1179113) & 4096) != 0 ? contentItem.ratingPercentage : null, ((-1179113) & 8192) != 0 ? contentItem.genres : null, ((-1179113) & 16384) != 0 ? contentItem.runtime : null, ((-1179113) & 32768) != 0 ? contentItem.cast : null, ((-1179113) & 65536) != 0 ? contentItem.certification : null, ((-1179113) & 131072) != 0 ? contentItem.imdbRating : null, ((-1179113) & MediaUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES) != 0 ? contentItem.rottenTomatoesRating : null, ((-1179113) & 524288) != 0 ? contentItem.traktRating : null, ((-1179113) & ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES) != 0 ? contentItem.watchProgress : null, ((-1179113) & 2097152) != 0 ? contentItem.continueWatchingPlaybackId : null, ((-1179113) & 4194304) != 0 ? contentItem.continueWatchingSeason : null, ((-1179113) & 8388608) != 0 ? contentItem.continueWatchingEpisode : null, ((-1179113) & Http2Connection.OKHTTP_CLIENT_WINDOW_SIZE) != 0 ? contentItem.continueWatchingIsRewatch : false, ((-1179113) & 33554432) != 0 ? contentItem.showTitle : null, ((-1179113) & C.BUFFER_FLAG_NOT_DEPENDED_ON) != 0 ? contentItem.sourceAddonUrl : null, ((-1179113) & C.BUFFER_FLAG_FIRST_SAMPLE) != 0 ? contentItem.directStreamUrl : null, ((-1179113) & 268435456) != 0 ? contentItem.calendarDate : null, ((-1179113) & 536870912) != 0 ? contentItem.calendarDayLabel : null, ((-1179113) & 1073741824) != 0 ? contentItem.calendarShowCount : 0, ((-1179113) & Integer.MIN_VALUE) != 0 ? contentItem.calendarEpisodes : null, (2047 & 1) != 0 ? contentItem.showStatus : null, (2047 & 2) != 0 ? contentItem.episodeIndicator : null, (2047 & 4) != 0 ? contentItem.unwatchedEpisodeCount : null, (2047 & 8) != 0 ? contentItem.addedAt : listedAt, (2047 & 16) != 0 ? contentItem.watchedAt : traktUserItem.getWatchedAt(), (2047 & 32) != 0 ? contentItem.watchers : null, (2047 & 64) != 0 ? contentItem.tagline : null, (2047 & 128) != 0 ? contentItem.stremioId : null, (2047 & 256) != 0 ? contentItem.stremioType : null, (2047 & 512) != 0 ? contentItem.extraData : null, (2047 & 1024) != 0 ? contentItem.focusGifUrl : null);
                    }
                    r2.release();
                    return contentItemCopy;
                }
                i = this.d;
                contentLoaderUseCase = this.c;
                traktUserItem = this.b;
                xf8 xf8Var3 = this.a;
                s38.b(obj);
                r8 = xf8Var3;
                String itemType = traktUserItem.getItemType();
                if (cr4.b(itemType, "MOVIE")) {
                    String title = traktUserItem.getTitle();
                    String year = traktUserItem.getYear();
                    Integer numBe = year != null ? n89.be(year) : null;
                    this.a = r8;
                    this.b = traktUserItem;
                    this.c = null;
                    this.e = 2;
                    objB = ContentLoaderUseCase.b(contentLoaderUseCase, i, title, numBe, this);
                    if (objB != ck1Var) {
                        traktUserItem2 = traktUserItem;
                        r82 = r8;
                        contentItem2 = (ContentItem) objB;
                        r84 = r82;
                        traktUserItem = traktUserItem2;
                        contentItem = contentItem2;
                        r83 = r84;
                        r2 = r83;
                        if (contentItem != null) {
                        }
                        r2.release();
                        return contentItemCopy;
                    }
                } else {
                    if (!cr4.b(itemType, "SHOW")) {
                        contentItem = null;
                        r83 = r8;
                        r2 = r83;
                        if (contentItem != null) {
                        }
                        r2.release();
                        return contentItemCopy;
                    }
                    String title2 = traktUserItem.getTitle();
                    String year2 = traktUserItem.getYear();
                    Integer numBe2 = year2 != null ? n89.be(year2) : null;
                    this.a = r8;
                    this.b = traktUserItem;
                    this.c = null;
                    this.e = 3;
                    objC = ContentLoaderUseCase.c(contentLoaderUseCase, i, title2, numBe2, this);
                    if (objC != ck1Var) {
                        traktUserItem2 = traktUserItem;
                        r85 = r8;
                        contentItem2 = (ContentItem) objC;
                        r84 = r85;
                        traktUserItem = traktUserItem2;
                        contentItem = contentItem2;
                        r83 = r84;
                        r2 = r83;
                        if (contentItem != null) {
                        }
                        r2.release();
                        return contentItemCopy;
                    }
                }
                return ck1Var;
            } catch (Throwable th) {
                th = th;
                r2 = r8;
                r2.release();
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }
}
