package com.strmr.ps.data.repository;

import androidx.media3.container.NalUnitUtil;
import com.strmr.ps.data.local.dao.TraktUserItemDao;
import com.strmr.ps.data.local.entity.TraktAccount;
import com.strmr.ps.data.model.ContentItem;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.fi7;
import defpackage.gr3;
import defpackage.kp6;
import defpackage.m02;
import defpackage.m12;
import defpackage.mg6;
import defpackage.pq6;
import defpackage.rg6;
import defpackage.s38;
import defpackage.sc2;
import defpackage.vx8;
import defpackage.wj0;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000P\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\f\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0007\b\u0007\u0018\u0000 02\u00020\u0001:\u000201B!\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\u0006\u0010\u0007\u001a\u00020\u0006¢\u0006\u0004\b\b\u0010\tJ\u0010\u0010\u000b\u001a\u00020\nH\u0082@¢\u0006\u0004\b\u000b\u0010\fJ\u0010\u0010\r\u001a\u00020\nH\u0082@¢\u0006\u0004\b\r\u0010\fJ\u0010\u0010\u000f\u001a\u00020\u000eH\u0086@¢\u0006\u0004\b\u000f\u0010\fJ \u0010\u0014\u001a\u00020\u000e2\u0006\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u0012H\u0086@¢\u0006\u0004\b\u0014\u0010\u0015J \u0010\u0016\u001a\u00020\u000e2\u0006\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u0012H\u0086@¢\u0006\u0004\b\u0016\u0010\u0015J \u0010\u0017\u001a\u00020\u000e2\u0006\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u0012H\u0086@¢\u0006\u0004\b\u0017\u0010\u0015J\u0015\u0010\u0018\u001a\u00020\n2\u0006\u0010\u0011\u001a\u00020\u0010¢\u0006\u0004\b\u0018\u0010\u0019J\u0015\u0010\u001a\u001a\u00020\n2\u0006\u0010\u0011\u001a\u00020\u0010¢\u0006\u0004\b\u001a\u0010\u0019J\u0015\u0010\u001b\u001a\u00020\n2\u0006\u0010\u0011\u001a\u00020\u0010¢\u0006\u0004\b\u001b\u0010\u0019J\u0015\u0010\u001c\u001a\u00020\n2\u0006\u0010\u0011\u001a\u00020\u0010¢\u0006\u0004\b\u001c\u0010\u0019J\u0015\u0010\u001d\u001a\u00020\n2\u0006\u0010\u0011\u001a\u00020\u0010¢\u0006\u0004\b\u001d\u0010\u0019J\u0015\u0010\u001e\u001a\u00020\n2\u0006\u0010\u0011\u001a\u00020\u0010¢\u0006\u0004\b\u001e\u0010\u0019J \u0010 \u001a\u00020\u001f2\u0006\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u0012H\u0086@¢\u0006\u0004\b \u0010\u0015J\u0010\u0010!\u001a\u00020\nH\u0086@¢\u0006\u0004\b!\u0010\fJ\r\u0010\"\u001a\u00020\n¢\u0006\u0004\b\"\u0010#R\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010$R\u0014\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0005\u0010%R\u0014\u0010\u0007\u001a\u00020\u00068\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0007\u0010&R \u0010(\u001a\u000e\u0012\u0004\u0012\u00020\u0010\u0012\u0004\u0012\u00020\u000e0'8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b(\u0010)R \u0010*\u001a\u000e\u0012\u0004\u0012\u00020\u0010\u0012\u0004\u0012\u00020\u000e0'8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b*\u0010)R\u0014\u0010,\u001a\u00020+8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b,\u0010-R\u0016\u0010.\u001a\u00020\u000e8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b.\u0010/¨\u00062"}, d2 = {"Lcom/strmr/ps/data/repository/TraktStatusProvider;", "", "Lcom/strmr/ps/data/local/dao/TraktUserItemDao;", "userItemDao", "Lcom/strmr/ps/data/repository/TraktAccountRepository;", "accountRepository", "Lcom/strmr/ps/data/repository/WatchStatusRepository;", "watchStatusRepository", "<init>", "(Lcom/strmr/ps/data/local/dao/TraktUserItemDao;Lcom/strmr/ps/data/repository/TraktAccountRepository;Lcom/strmr/ps/data/repository/WatchStatusRepository;)V", "Le6a;", "ensureCacheLoaded", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "loadCacheFromDatabase", "", "isAuthenticated", "", "tmdbId", "Lcom/strmr/ps/data/model/ContentItem$ItemType;", "itemType", "isWatched", "(ILcom/strmr/ps/data/model/ContentItem$ItemType;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "isInCollection", "isInWatchlist", "markWatched", "(I)V", "markUnwatched", "addToCollection", "removeFromCollection", "addToWatchlist", "removeFromWatchlist", "Lcom/strmr/ps/data/repository/TraktStatusProvider$ItemStatus;", "getItemStatus", "refreshCache", "clearCache", "()V", "Lcom/strmr/ps/data/local/dao/TraktUserItemDao;", "Lcom/strmr/ps/data/repository/TraktAccountRepository;", "Lcom/strmr/ps/data/repository/WatchStatusRepository;", "Ljava/util/concurrent/ConcurrentHashMap;", "collectionCache", "Ljava/util/concurrent/ConcurrentHashMap;", "watchlistCache", "Lmg6;", "cacheMutex", "Lmg6;", "cacheInitialized", "Z", "Companion", "ItemStatus", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class TraktStatusProvider {

    @kp6
    private static final String LIST_COLLECTION = "COLLECTION";

    @kp6
    private static final String LIST_WATCHLIST = "WATCHLIST";

    @kp6
    private final TraktAccountRepository accountRepository;
    private boolean cacheInitialized;

    @kp6
    private final mg6 cacheMutex;

    @kp6
    private final ConcurrentHashMap<Integer, Boolean> collectionCache;

    @kp6
    private final TraktUserItemDao userItemDao;

    @kp6
    private final WatchStatusRepository watchStatusRepository;

    @kp6
    private final ConcurrentHashMap<Integer, Boolean> watchlistCache;

    @Metadata(d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000b\n\u0002\b\f\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0000\b\u0086\b\u0018\u00002\u00020\u0001B\u001f\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003\u0012\u0006\u0010\u0005\u001a\u00020\u0003¢\u0006\u0004\b\u0006\u0010\u0007J\t\u0010\t\u001a\u00020\u0003HÆ\u0003J\t\u0010\n\u001a\u00020\u0003HÆ\u0003J\t\u0010\u000b\u001a\u00020\u0003HÆ\u0003J'\u0010\f\u001a\u00020\u00002\b\b\u0002\u0010\u0002\u001a\u00020\u00032\b\b\u0002\u0010\u0004\u001a\u00020\u00032\b\b\u0002\u0010\u0005\u001a\u00020\u0003HÆ\u0001J\u0013\u0010\r\u001a\u00020\u00032\b\u0010\u000e\u001a\u0004\u0018\u00010\u0001HÖ\u0003J\t\u0010\u000f\u001a\u00020\u0010HÖ\u0001J\t\u0010\u0011\u001a\u00020\u0012HÖ\u0001R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0002\u0010\bR\u0011\u0010\u0004\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0004\u0010\bR\u0011\u0010\u0005\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0005\u0010\b¨\u0006\u0013"}, d2 = {"Lcom/strmr/ps/data/repository/TraktStatusProvider$ItemStatus;", "", "isWatched", "", "isInCollection", "isInWatchlist", "<init>", "(ZZZ)V", "()Z", "component1", "component2", "component3", "copy", "equals", "other", "hashCode", "", "toString", "", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final /* data */ class ItemStatus {
        private final boolean isInCollection;
        private final boolean isInWatchlist;
        private final boolean isWatched;

        public ItemStatus(boolean z, boolean z2, boolean z3) {
            this.isWatched = z;
            this.isInCollection = z2;
            this.isInWatchlist = z3;
        }

        public static /* synthetic */ ItemStatus copy$default(ItemStatus itemStatus, boolean z, boolean z2, boolean z3, int i, Object obj) {
            if ((i & 1) != 0) {
                z = itemStatus.isWatched;
            }
            if ((i & 2) != 0) {
                z2 = itemStatus.isInCollection;
            }
            if ((i & 4) != 0) {
                z3 = itemStatus.isInWatchlist;
            }
            return itemStatus.copy(z, z2, z3);
        }

        /* JADX INFO: renamed from: component1, reason: from getter */
        public final boolean getIsWatched() {
            return this.isWatched;
        }

        /* JADX INFO: renamed from: component2, reason: from getter */
        public final boolean getIsInCollection() {
            return this.isInCollection;
        }

        /* JADX INFO: renamed from: component3, reason: from getter */
        public final boolean getIsInWatchlist() {
            return this.isInWatchlist;
        }

        @kp6
        public final ItemStatus copy(boolean isWatched, boolean isInCollection, boolean isInWatchlist) {
            return new ItemStatus(isWatched, isInCollection, isInWatchlist);
        }

        public boolean equals(@pq6 Object other) {
            if (this == other) {
                return true;
            }
            if (!(other instanceof ItemStatus)) {
                return false;
            }
            ItemStatus itemStatus = (ItemStatus) other;
            return this.isWatched == itemStatus.isWatched && this.isInCollection == itemStatus.isInCollection && this.isInWatchlist == itemStatus.isInWatchlist;
        }

        public int hashCode() {
            return Boolean.hashCode(this.isInWatchlist) + fi7.c(Boolean.hashCode(this.isWatched) * 31, 31, this.isInCollection);
        }

        public final boolean isInCollection() {
            return this.isInCollection;
        }

        public final boolean isInWatchlist() {
            return this.isInWatchlist;
        }

        public final boolean isWatched() {
            return this.isWatched;
        }

        @kp6
        public String toString() {
            return "ItemStatus(isWatched=" + this.isWatched + ", isInCollection=" + this.isInCollection + ", isInWatchlist=" + this.isInWatchlist + ")";
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TraktStatusProvider$ensureCacheLoaded$1, reason: invalid class name */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TraktStatusProvider", f = "TraktStatusProvider.kt", i = {0, 0, 1}, l = {193, 159}, m = "ensureCacheLoaded", n = {"this", "$this$withLock_u24default$iv", "$this$withLock_u24default$iv"}, s = {"L$0", "L$1", "L$0"})
    public static final class AnonymousClass1 extends ContinuationImpl {
        Object L$0;
        Object L$1;
        int label;
        /* synthetic */ Object result;

        public AnonymousClass1(Continuation<? super AnonymousClass1> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TraktStatusProvider.this.ensureCacheLoaded(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TraktStatusProvider$getItemStatus$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TraktStatusProvider", f = "TraktStatusProvider.kt", i = {0, 0, 0}, l = {123}, m = "getItemStatus", n = {"this", "itemType", "tmdbId"}, s = {"L$0", "L$1", "I$0"})
    public static final class C04541 extends ContinuationImpl {
        int I$0;
        Object L$0;
        Object L$1;
        int label;
        /* synthetic */ Object result;

        public C04541(Continuation<? super C04541> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TraktStatusProvider.this.getItemStatus(0, null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TraktStatusProvider$isAuthenticated$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TraktStatusProvider", f = "TraktStatusProvider.kt", i = {}, l = {41}, m = "isAuthenticated", n = {}, s = {})
    public static final class C04551 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C04551(Continuation<? super C04551> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TraktStatusProvider.this.isAuthenticated(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TraktStatusProvider$isInCollection$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TraktStatusProvider", f = "TraktStatusProvider.kt", i = {0, 0}, l = {61}, m = "isInCollection", n = {"this", "tmdbId"}, s = {"L$0", "I$0"})
    public static final class C04561 extends ContinuationImpl {
        int I$0;
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public C04561(Continuation<? super C04561> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TraktStatusProvider.this.isInCollection(0, null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TraktStatusProvider$isInWatchlist$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TraktStatusProvider", f = "TraktStatusProvider.kt", i = {0, 0}, l = {69}, m = "isInWatchlist", n = {"this", "tmdbId"}, s = {"L$0", "I$0"})
    public static final class C04571 extends ContinuationImpl {
        int I$0;
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public C04571(Continuation<? super C04571> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TraktStatusProvider.this.isInWatchlist(0, null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TraktStatusProvider$loadCacheFromDatabase$2, reason: invalid class name */
    @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.data.repository.TraktStatusProvider$loadCacheFromDatabase$2", f = "TraktStatusProvider.kt", i = {1, 2}, l = {168, 169, 170}, m = "invokeSuspend", n = {"userSlug", "collectionIds"}, s = {"L$0", "L$0"})
    @vx8
    public static final class AnonymousClass2 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
        Object L$0;
        int label;

        public AnonymousClass2(Continuation<? super AnonymousClass2> continuation) {
            super(2, continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return TraktStatusProvider.this.new AnonymousClass2(continuation);
        }

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

        /* JADX WARN: Removed duplicated region for block: B:26:0x0073  */
        /* JADX WARN: Removed duplicated region for block: B:30:0x008e A[LOOP:0: B:28:0x0088->B:30:0x008e, LOOP_END] */
        /* JADX WARN: Removed duplicated region for block: B:34:0x00bf A[LOOP:1: B:32:0x00b9->B:34:0x00bf, LOOP_END] */
        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            String userSlug;
            Object allTmdbIdsInList;
            List list;
            Iterator it;
            Iterator it2;
            ck1 ck1Var = ck1.a;
            int i = this.label;
            e6a e6aVar = e6a.a;
            if (i == 0) {
                s38.b(obj);
                TraktAccountRepository traktAccountRepository = TraktStatusProvider.this.accountRepository;
                this.label = 1;
                obj = traktAccountRepository.getActiveAccount(this);
                if (obj != ck1Var) {
                }
                return ck1Var;
            }
            if (i != 1) {
                if (i != 2) {
                    if (i != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    list = (List) this.L$0;
                    s38.b(obj);
                    List list2 = (List) obj;
                    TraktStatusProvider.this.collectionCache.clear();
                    TraktStatusProvider traktStatusProvider = TraktStatusProvider.this;
                    it = list.iterator();
                    while (it.hasNext()) {
                        traktStatusProvider.collectionCache.put(Boxing.boxInt(((Number) it.next()).intValue()), Boxing.boxBoolean(true));
                    }
                    TraktStatusProvider.this.watchlistCache.clear();
                    TraktStatusProvider traktStatusProvider2 = TraktStatusProvider.this;
                    it2 = list2.iterator();
                    while (it2.hasNext()) {
                        traktStatusProvider2.watchlistCache.put(Boxing.boxInt(((Number) it2.next()).intValue()), Boxing.boxBoolean(true));
                    }
                    TraktStatusProvider.this.cacheInitialized = true;
                    return e6aVar;
                }
                userSlug = (String) this.L$0;
                s38.b(obj);
                List list3 = (List) obj;
                TraktUserItemDao traktUserItemDao = TraktStatusProvider.this.userItemDao;
                this.L$0 = list3;
                this.label = 3;
                allTmdbIdsInList = traktUserItemDao.getAllTmdbIdsInList(TraktStatusProvider.LIST_WATCHLIST, userSlug, this);
                if (allTmdbIdsInList != ck1Var) {
                    list = list3;
                    obj = allTmdbIdsInList;
                    List list22 = (List) obj;
                    TraktStatusProvider.this.collectionCache.clear();
                    TraktStatusProvider traktStatusProvider3 = TraktStatusProvider.this;
                    it = list.iterator();
                    while (it.hasNext()) {
                    }
                    TraktStatusProvider.this.watchlistCache.clear();
                    TraktStatusProvider traktStatusProvider22 = TraktStatusProvider.this;
                    it2 = list22.iterator();
                    while (it2.hasNext()) {
                    }
                    TraktStatusProvider.this.cacheInitialized = true;
                    return e6aVar;
                }
                return ck1Var;
            }
            s38.b(obj);
            TraktAccount traktAccount = (TraktAccount) obj;
            if (traktAccount != null && (userSlug = traktAccount.getUserSlug()) != null) {
                TraktUserItemDao traktUserItemDao2 = TraktStatusProvider.this.userItemDao;
                this.L$0 = userSlug;
                this.label = 2;
                obj = traktUserItemDao2.getAllTmdbIdsInList(TraktStatusProvider.LIST_COLLECTION, userSlug, this);
                if (obj != ck1Var) {
                    List list32 = (List) obj;
                    TraktUserItemDao traktUserItemDao3 = TraktStatusProvider.this.userItemDao;
                    this.L$0 = list32;
                    this.label = 3;
                    allTmdbIdsInList = traktUserItemDao3.getAllTmdbIdsInList(TraktStatusProvider.LIST_WATCHLIST, userSlug, this);
                    if (allTmdbIdsInList != ck1Var) {
                    }
                }
                return ck1Var;
            }
            return e6aVar;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TraktStatusProvider$refreshCache$2, reason: invalid class name and case insensitive filesystem */
    @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.data.repository.TraktStatusProvider$refreshCache$2", f = "TraktStatusProvider.kt", i = {0, 1}, l = {193, 141}, m = "invokeSuspend", n = {"$this$withLock_u24default$iv", "$this$withLock_u24default$iv"}, s = {"L$0", "L$0"})
    @vx8
    public static final class C04582 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
        Object L$0;
        Object L$1;
        int label;

        public C04582(Continuation<? super C04582> continuation) {
            super(2, continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return TraktStatusProvider.this.new C04582(continuation);
        }

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

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            mg6 mg6Var;
            TraktStatusProvider traktStatusProvider;
            mg6 mg6Var2;
            Throwable th;
            ck1 ck1Var = ck1.a;
            int i = this.label;
            try {
                if (i == 0) {
                    s38.b(obj);
                    mg6Var = TraktStatusProvider.this.cacheMutex;
                    traktStatusProvider = TraktStatusProvider.this;
                    this.L$0 = mg6Var;
                    this.L$1 = traktStatusProvider;
                    this.label = 1;
                    if (mg6Var.a(this) != ck1Var) {
                    }
                    return ck1Var;
                }
                if (i != 1) {
                    if (i != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    mg6Var2 = (mg6) this.L$0;
                    try {
                        s38.b(obj);
                        mg6Var2.c(null);
                        return e6a.a;
                    } catch (Throwable th2) {
                        th = th2;
                        mg6Var2.c(null);
                        throw th;
                    }
                }
                traktStatusProvider = (TraktStatusProvider) this.L$1;
                mg6 mg6Var3 = (mg6) this.L$0;
                s38.b(obj);
                mg6Var = mg6Var3;
                this.L$0 = mg6Var;
                this.L$1 = null;
                this.label = 2;
                if (traktStatusProvider.loadCacheFromDatabase(this) != ck1Var) {
                    mg6Var2 = mg6Var;
                    mg6Var2.c(null);
                    return e6a.a;
                }
                return ck1Var;
            } catch (Throwable th3) {
                mg6Var2 = mg6Var;
                th = th3;
                mg6Var2.c(null);
                throw th;
            }
        }
    }

    @Inject
    public TraktStatusProvider(@kp6 TraktUserItemDao traktUserItemDao, @kp6 TraktAccountRepository traktAccountRepository, @kp6 WatchStatusRepository watchStatusRepository) {
        cr4.g(traktUserItemDao, "userItemDao");
        cr4.g(traktAccountRepository, "accountRepository");
        cr4.g(watchStatusRepository, "watchStatusRepository");
        this.userItemDao = traktUserItemDao;
        this.accountRepository = traktAccountRepository;
        this.watchStatusRepository = watchStatusRepository;
        this.collectionCache = new ConcurrentHashMap<>();
        this.watchlistCache = new ConcurrentHashMap<>();
        this.cacheMutex = rg6.a();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object ensureCacheLoaded(Continuation<? super e6a> continuation) throws Throwable {
        AnonymousClass1 anonymousClass1;
        mg6 mg6Var;
        TraktStatusProvider traktStatusProvider;
        mg6 mg6Var2;
        Throwable th;
        if (continuation instanceof AnonymousClass1) {
            anonymousClass1 = (AnonymousClass1) continuation;
            int i = anonymousClass1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                anonymousClass1.label = i - Integer.MIN_VALUE;
            } else {
                anonymousClass1 = new AnonymousClass1(continuation);
            }
        }
        Object obj = anonymousClass1.result;
        ck1 ck1Var = ck1.a;
        int i2 = anonymousClass1.label;
        try {
            if (i2 == 0) {
                s38.b(obj);
                if (!this.cacheInitialized) {
                    mg6Var = this.cacheMutex;
                    anonymousClass1.L$0 = this;
                    anonymousClass1.L$1 = mg6Var;
                    anonymousClass1.label = 1;
                    if (mg6Var.a(anonymousClass1) != ck1Var) {
                        traktStatusProvider = this;
                    }
                    return ck1Var;
                }
                return e6a.a;
            }
            if (i2 != 1) {
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                mg6Var2 = (mg6) anonymousClass1.L$0;
                try {
                    s38.b(obj);
                    mg6Var = mg6Var2;
                    mg6Var.c(null);
                    return e6a.a;
                } catch (Throwable th2) {
                    th = th2;
                    mg6Var2.c(null);
                    throw th;
                }
            }
            mg6 mg6Var3 = (mg6) anonymousClass1.L$1;
            traktStatusProvider = (TraktStatusProvider) anonymousClass1.L$0;
            s38.b(obj);
            mg6Var = mg6Var3;
            if (!traktStatusProvider.cacheInitialized) {
                anonymousClass1.L$0 = mg6Var;
                anonymousClass1.L$1 = null;
                anonymousClass1.label = 2;
                if (traktStatusProvider.loadCacheFromDatabase(anonymousClass1) != ck1Var) {
                    mg6Var2 = mg6Var;
                    mg6Var = mg6Var2;
                }
                return ck1Var;
            }
            mg6Var.c(null);
            return e6a.a;
        } catch (Throwable th3) {
            mg6Var2 = mg6Var;
            th = th3;
            mg6Var2.c(null);
            throw th;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Object loadCacheFromDatabase(Continuation<? super e6a> continuation) throws Throwable {
        m12 m12Var = sc2.a;
        Object objF = wj0.f(m02.c, new AnonymousClass2(null), continuation);
        return objF == ck1.a ? objF : e6a.a;
    }

    public final void addToCollection(int tmdbId) {
        this.collectionCache.put(Integer.valueOf(tmdbId), Boolean.TRUE);
    }

    public final void addToWatchlist(int tmdbId) {
        this.watchlistCache.put(Integer.valueOf(tmdbId), Boolean.TRUE);
    }

    public final void clearCache() {
        this.collectionCache.clear();
        this.watchlistCache.clear();
        this.cacheInitialized = false;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object getItemStatus(int i, @kp6 ContentItem.ItemType itemType, @kp6 Continuation<? super ItemStatus> continuation) {
        C04541 c04541;
        TraktStatusProvider traktStatusProvider;
        if (continuation instanceof C04541) {
            c04541 = (C04541) continuation;
            int i2 = c04541.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                c04541.label = i2 - Integer.MIN_VALUE;
            } else {
                c04541 = new C04541(continuation);
            }
        }
        Object obj = c04541.result;
        ck1 ck1Var = ck1.a;
        int i3 = c04541.label;
        if (i3 == 0) {
            s38.b(obj);
            c04541.L$0 = this;
            c04541.L$1 = itemType;
            c04541.I$0 = i;
            c04541.label = 1;
            if (ensureCacheLoaded(c04541) == ck1Var) {
                return ck1Var;
            }
            traktStatusProvider = this;
        } else {
            if (i3 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i = c04541.I$0;
            itemType = (ContentItem.ItemType) c04541.L$1;
            traktStatusProvider = (TraktStatusProvider) c04541.L$0;
            s38.b(obj);
        }
        Double progress = traktStatusProvider.watchStatusRepository.getProgress(i, itemType);
        boolean z = progress != null && progress.doubleValue() >= (itemType == ContentItem.ItemType.TV_SHOW ? 1.0d : 0.9d);
        Boolean bool = traktStatusProvider.collectionCache.get(Boxing.boxInt(i));
        boolean zBooleanValue = bool != null ? bool.booleanValue() : false;
        Boolean bool2 = traktStatusProvider.watchlistCache.get(Boxing.boxInt(i));
        return new ItemStatus(z, zBooleanValue, bool2 != null ? bool2.booleanValue() : false);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object isAuthenticated(@kp6 Continuation<? super Boolean> continuation) {
        C04551 c04551;
        if (continuation instanceof C04551) {
            c04551 = (C04551) continuation;
            int i = c04551.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c04551.label = i - Integer.MIN_VALUE;
            } else {
                c04551 = new C04551(continuation);
            }
        }
        Object activeAccount = c04551.result;
        ck1 ck1Var = ck1.a;
        int i2 = c04551.label;
        if (i2 == 0) {
            s38.b(activeAccount);
            TraktAccountRepository traktAccountRepository = this.accountRepository;
            c04551.label = 1;
            activeAccount = traktAccountRepository.getActiveAccount(c04551);
            if (activeAccount == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(activeAccount);
        }
        return Boxing.boxBoolean(activeAccount != null);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object isInCollection(int i, @kp6 ContentItem.ItemType itemType, @kp6 Continuation<? super Boolean> continuation) {
        C04561 c04561;
        TraktStatusProvider traktStatusProvider;
        if (continuation instanceof C04561) {
            c04561 = (C04561) continuation;
            int i2 = c04561.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                c04561.label = i2 - Integer.MIN_VALUE;
            } else {
                c04561 = new C04561(continuation);
            }
        }
        Object obj = c04561.result;
        ck1 ck1Var = ck1.a;
        int i3 = c04561.label;
        if (i3 == 0) {
            s38.b(obj);
            c04561.L$0 = this;
            c04561.I$0 = i;
            c04561.label = 1;
            if (ensureCacheLoaded(c04561) == ck1Var) {
                return ck1Var;
            }
            traktStatusProvider = this;
        } else {
            if (i3 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i = c04561.I$0;
            traktStatusProvider = (TraktStatusProvider) c04561.L$0;
            s38.b(obj);
        }
        Boolean bool = traktStatusProvider.collectionCache.get(Boxing.boxInt(i));
        return Boxing.boxBoolean(bool != null ? bool.booleanValue() : false);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object isInWatchlist(int i, @kp6 ContentItem.ItemType itemType, @kp6 Continuation<? super Boolean> continuation) {
        C04571 c04571;
        TraktStatusProvider traktStatusProvider;
        if (continuation instanceof C04571) {
            c04571 = (C04571) continuation;
            int i2 = c04571.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                c04571.label = i2 - Integer.MIN_VALUE;
            } else {
                c04571 = new C04571(continuation);
            }
        }
        Object obj = c04571.result;
        ck1 ck1Var = ck1.a;
        int i3 = c04571.label;
        if (i3 == 0) {
            s38.b(obj);
            c04571.L$0 = this;
            c04571.I$0 = i;
            c04571.label = 1;
            if (ensureCacheLoaded(c04571) == ck1Var) {
                return ck1Var;
            }
            traktStatusProvider = this;
        } else {
            if (i3 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i = c04571.I$0;
            traktStatusProvider = (TraktStatusProvider) c04571.L$0;
            s38.b(obj);
        }
        Boolean bool = traktStatusProvider.watchlistCache.get(Boxing.boxInt(i));
        return Boxing.boxBoolean(bool != null ? bool.booleanValue() : false);
    }

    @pq6
    public final Object isWatched(int i, @kp6 ContentItem.ItemType itemType, @kp6 Continuation<? super Boolean> continuation) {
        Double progress = this.watchStatusRepository.getProgress(i, itemType);
        if (progress == null) {
            return Boxing.boxBoolean(false);
        }
        return Boxing.boxBoolean(progress.doubleValue() >= (itemType == ContentItem.ItemType.TV_SHOW ? 1.0d : 0.9d));
    }

    public final void markUnwatched(int tmdbId) {
    }

    public final void markWatched(int tmdbId) {
    }

    @pq6
    public final Object refreshCache(@kp6 Continuation<? super e6a> continuation) throws Throwable {
        m12 m12Var = sc2.a;
        Object objF = wj0.f(m02.c, new C04582(null), continuation);
        return objF == ck1.a ? objF : e6a.a;
    }

    public final void removeFromCollection(int tmdbId) {
        this.collectionCache.remove(Integer.valueOf(tmdbId));
    }

    public final void removeFromWatchlist(int tmdbId) {
        this.watchlistCache.remove(Integer.valueOf(tmdbId));
    }
}
