package com.strmr.ps.data.repository;

import android.util.Log;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.tmdb.TMDBExternalIds;
import com.strmr.ps.data.model.tmdb.TMDBGenre;
import com.strmr.ps.data.model.tmdb.TMDBShowDetails;
import com.strmr.ps.data.remote.api.TMDBApiService;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.s38;
import defpackage.y41;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
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\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.data.repository.ContentRepository$fetchShowsByGenreFromApis$2$1$1", f = "ContentRepository.kt", i = {}, l = {614}, m = "invokeSuspend", n = {}, s = {})
public final class ContentRepository$fetchShowsByGenreFromApis$2$1$1 extends SuspendLambda implements gr3<ak1, Continuation<? super ContentItem>, Object> {
    final /* synthetic */ int $tmdbId;
    int label;
    final /* synthetic */ ContentRepository this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ContentRepository$fetchShowsByGenreFromApis$2$1$1(ContentRepository contentRepository, int i, Continuation<? super ContentRepository$fetchShowsByGenreFromApis$2$1$1> continuation) {
        super(2, continuation);
        this.this$0 = contentRepository;
        this.$tmdbId = i;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
        return new ContentRepository$fetchShowsByGenreFromApis$2$1$1(this.this$0, this.$tmdbId, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(ak1 ak1Var, Continuation<? super ContentItem> continuation) {
        return ((ContentRepository$fetchShowsByGenreFromApis$2$1$1) create(ak1Var, continuation)).invokeSuspend(e6a.a);
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) {
        Object showDetails;
        ck1 ck1Var = ck1.a;
        int i = this.label;
        try {
            if (i == 0) {
                s38.b(obj);
                TMDBApiService tMDBApiService = this.this$0.tmdbApiService;
                int i2 = this.$tmdbId;
                this.label = 1;
                showDetails = tMDBApiService.getShowDetails(i2, "images,external_ids,credits,content_ratings", this);
                if (showDetails == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
                showDetails = obj;
            }
            TMDBShowDetails tMDBShowDetails = (TMDBShowDetails) showDetails;
            int i3 = this.$tmdbId;
            ContentItem.ItemType itemType = ContentItem.ItemType.TV_SHOW;
            ContentRepository contentRepository = this.this$0;
            TMDBExternalIds externalIds = tMDBShowDetails.getExternalIds();
            String strResolveImdbId = contentRepository.resolveImdbId(null, externalIds != null ? externalIds.getImdbId() : null, null);
            String name = tMDBShowDetails.getName();
            String overview = tMDBShowDetails.getOverview();
            String posterUrl = tMDBShowDetails.getPosterUrl(this.this$0.getImgLang());
            String backdropUrl = tMDBShowDetails.getBackdropUrl(this.this$0.getImgLang());
            String logoUrl = tMDBShowDetails.getLogoUrl(this.this$0.getImgLang());
            String year = tMDBShowDetails.getYear();
            Double voteAverage = tMDBShowDetails.getVoteAverage();
            Integer ratingPercentage = tMDBShowDetails.getRatingPercentage();
            List<TMDBGenre> genres = tMDBShowDetails.getGenres();
            String strAi = genres != null ? y41.ai(genres, ", ", null, null, new a(10), 30) : null;
            ContentRepository contentRepository2 = this.this$0;
            List<Integer> episodeRunTime = tMDBShowDetails.getEpisodeRunTime();
            return new ContentItem(i3, itemType, i3, strResolveImdbId, name, overview, posterUrl, backdropUrl, logoUrl, null, year, voteAverage, ratingPercentage, strAi, contentRepository2.formatRuntime(episodeRunTime != null ? (Integer) y41.ab(episodeRunTime) : null), TMDBShowDetails.getCastNames$default(tMDBShowDetails, 0, 1, null), tMDBShowDetails.getCertification(), null, null, null, this.this$0.watchStatusRepository.getProgress(this.$tmdbId, itemType), null, null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -2096640, 2047, null);
        } catch (Exception e) {
            Log.e("ContentRepository", "Error fetching TMDB details for show " + this.$tmdbId, e);
            return null;
        }
    }
}
