package com.strmr.ps.data.repository;

import android.util.Log;
import androidx.media3.container.NalUnitUtil;
import com.google.android.gms.common.internal.ImagesContract;
import com.strmr.ps.data.local.dao.ContentImageOverrideDao;
import com.strmr.ps.data.local.entity.ContentImageOverrideEntity;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gg6;
import defpackage.k63;
import defpackage.kp6;
import defpackage.pq6;
import defpackage.s38;
import defpackage.ug0;
import defpackage.up8;
import defpackage.vp8;
import defpackage.vx8;
import defpackage.xp8;
import java.util.List;
import java.util.concurrent.CancellationException;
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.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import net.zetetic.database.DatabaseUtils;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000F\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0004\n\u0002\u0010\u000b\n\u0002\b\r\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0007\u0018\u00002\u00020\u0001B\u0011\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002¢\u0006\u0004\b\u0004\u0010\u0005J\u0010\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0007\u0010\bJ!\u0010\r\u001a\u0004\u0018\u00010\u000b2\u0006\u0010\n\u001a\u00020\t2\b\u0010\f\u001a\u0004\u0018\u00010\u000b¢\u0006\u0004\b\r\u0010\u000eJ!\u0010\u000f\u001a\u0004\u0018\u00010\u000b2\u0006\u0010\n\u001a\u00020\t2\b\u0010\f\u001a\u0004\u0018\u00010\u000b¢\u0006\u0004\b\u000f\u0010\u000eJ\u0015\u0010\u0011\u001a\u00020\u00102\u0006\u0010\n\u001a\u00020\t¢\u0006\u0004\b\u0011\u0010\u0012J\u0015\u0010\u0013\u001a\u00020\u00102\u0006\u0010\n\u001a\u00020\t¢\u0006\u0004\b\u0013\u0010\u0012J\u0015\u0010\u0014\u001a\u00020\u00102\u0006\u0010\n\u001a\u00020\t¢\u0006\u0004\b\u0014\u0010\u0012J(\u0010\u0017\u001a\u00020\u00062\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u0015\u001a\u00020\u000b2\u0006\u0010\u0016\u001a\u00020\u000bH\u0086@¢\u0006\u0004\b\u0017\u0010\u0018J \u0010\u0019\u001a\u00020\u00062\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u0015\u001a\u00020\u000bH\u0086@¢\u0006\u0004\b\u0019\u0010\u001aJ\u0018\u0010\u001b\u001a\u00020\u00062\u0006\u0010\n\u001a\u00020\tH\u0086@¢\u0006\u0004\b\u001b\u0010\u001cR\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010\u001dR \u0010\u001f\u001a\u000e\u0012\u0004\u0012\u00020\u000b\u0012\u0004\u0012\u00020\u000b0\u001e8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001f\u0010 R\u001a\u0010\"\u001a\b\u0012\u0004\u0012\u00020\u00060!8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\"\u0010#R\u001d\u0010%\u001a\b\u0012\u0004\u0012\u00020\u00060$8\u0006¢\u0006\f\n\u0004\b%\u0010&\u001a\u0004\b'\u0010(¨\u0006)"}, d2 = {"Lcom/strmr/ps/data/repository/ContentImageOverrideRepository;", "", "Lcom/strmr/ps/data/local/dao/ContentImageOverrideDao;", "dao", "<init>", "(Lcom/strmr/ps/data/local/dao/ContentImageOverrideDao;)V", "Le6a;", "loadAll", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "", "tmdbId", "", "defaultUrl", "getPosterUrl", "(ILjava/lang/String;)Ljava/lang/String;", "getBackdropUrl", "", "hasPosterOverride", "(I)Z", "hasBackdropOverride", "hasAnyOverride", "imageType", ImagesContract.URL, "setOverride", "(ILjava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "resetOverride", "(ILjava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "resetAllOverrides", "(ILkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Lcom/strmr/ps/data/local/dao/ContentImageOverrideDao;", "Ljava/util/concurrent/ConcurrentHashMap;", "overrides", "Ljava/util/concurrent/ConcurrentHashMap;", "Lgg6;", "_overrideChanged", "Lgg6;", "Lup8;", "overrideChanged", "Lup8;", "getOverrideChanged", "()Lup8;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class ContentImageOverrideRepository {

    @kp6
    private final gg6<e6a> _overrideChanged;

    @kp6
    private final ContentImageOverrideDao dao;

    @kp6
    private final up8<e6a> overrideChanged;

    @kp6
    private final ConcurrentHashMap<String, String> overrides;

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContentImageOverrideRepository$loadAll$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.ContentImageOverrideRepository", f = "ContentImageOverrideRepository.kt", i = {0}, l = {35}, m = "loadAll", n = {"this"}, s = {"L$0"})
    public static final class AnonymousClass1 extends ContinuationImpl {
        Object L$0;
        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 ContentImageOverrideRepository.this.loadAll(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContentImageOverrideRepository$resetAllOverrides$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.ContentImageOverrideRepository", f = "ContentImageOverrideRepository.kt", i = {0, 0}, l = {DatabaseUtils.STATEMENT_OTHER}, m = "resetAllOverrides", n = {"this", "tmdbId"}, s = {"L$0", "I$0"})
    public static final class C02911 extends ContinuationImpl {
        int I$0;
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public C02911(Continuation<? super C02911> 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 ContentImageOverrideRepository.this.resetAllOverrides(0, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContentImageOverrideRepository$resetOverride$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.ContentImageOverrideRepository", f = "ContentImageOverrideRepository.kt", i = {0, 0, 0}, l = {86}, m = "resetOverride", n = {"this", "imageType", "tmdbId"}, s = {"L$0", "L$1", "I$0"})
    public static final class C02921 extends ContinuationImpl {
        int I$0;
        Object L$0;
        Object L$1;
        int label;
        /* synthetic */ Object result;

        public C02921(Continuation<? super C02921> 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 ContentImageOverrideRepository.this.resetOverride(0, null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContentImageOverrideRepository$setOverride$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.ContentImageOverrideRepository", f = "ContentImageOverrideRepository.kt", i = {0, 0, 0}, l = {73}, m = "setOverride", n = {"this", ImagesContract.URL, "entity"}, s = {"L$0", "L$1", "L$2"})
    public static final class C02931 extends ContinuationImpl {
        Object L$0;
        Object L$1;
        Object L$2;
        int label;
        /* synthetic */ Object result;

        public C02931(Continuation<? super C02931> 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 ContentImageOverrideRepository.this.setOverride(0, null, null, this);
        }
    }

    @Inject
    public ContentImageOverrideRepository(@kp6 ContentImageOverrideDao contentImageOverrideDao) {
        cr4.g(contentImageOverrideDao, "dao");
        this.dao = contentImageOverrideDao;
        this.overrides = new ConcurrentHashMap<>();
        vp8 vp8VarA = xp8.a(0, 1, ug0.b);
        this._overrideChanged = vp8VarA;
        this.overrideChanged = k63.a(vp8VarA);
    }

    @pq6
    public final String getBackdropUrl(int tmdbId, @pq6 String defaultUrl) {
        String str;
        return (tmdbId > 0 && (str = this.overrides.get(ContentImageOverrideEntity.INSTANCE.generateKey(tmdbId, ContentImageOverrideEntity.TYPE_BACKDROP))) != null) ? str : defaultUrl;
    }

    @kp6
    public final up8<e6a> getOverrideChanged() {
        return this.overrideChanged;
    }

    @pq6
    public final String getPosterUrl(int tmdbId, @pq6 String defaultUrl) {
        String str;
        return (tmdbId > 0 && (str = this.overrides.get(ContentImageOverrideEntity.INSTANCE.generateKey(tmdbId, ContentImageOverrideEntity.TYPE_POSTER))) != null) ? str : defaultUrl;
    }

    public final boolean hasAnyOverride(int tmdbId) {
        return hasPosterOverride(tmdbId) || hasBackdropOverride(tmdbId);
    }

    public final boolean hasBackdropOverride(int tmdbId) {
        return tmdbId > 0 && this.overrides.containsKey(ContentImageOverrideEntity.INSTANCE.generateKey(tmdbId, ContentImageOverrideEntity.TYPE_BACKDROP));
    }

    public final boolean hasPosterOverride(int tmdbId) {
        return tmdbId > 0 && this.overrides.containsKey(ContentImageOverrideEntity.INSTANCE.generateKey(tmdbId, ContentImageOverrideEntity.TYPE_POSTER));
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object loadAll(@kp6 Continuation<? super e6a> continuation) {
        AnonymousClass1 anonymousClass1;
        ContentImageOverrideRepository contentImageOverrideRepository;
        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 all = anonymousClass1.result;
        ck1 ck1Var = ck1.a;
        int i2 = anonymousClass1.label;
        try {
            if (i2 == 0) {
                s38.b(all);
                ContentImageOverrideDao contentImageOverrideDao = this.dao;
                anonymousClass1.L$0 = this;
                anonymousClass1.label = 1;
                all = contentImageOverrideDao.getAll(anonymousClass1);
                if (all == ck1Var) {
                    return ck1Var;
                }
                contentImageOverrideRepository = this;
            } else {
                if (i2 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                contentImageOverrideRepository = (ContentImageOverrideRepository) anonymousClass1.L$0;
                s38.b(all);
            }
            contentImageOverrideRepository.overrides.clear();
            for (ContentImageOverrideEntity contentImageOverrideEntity : (List) all) {
                contentImageOverrideRepository.overrides.put(contentImageOverrideEntity.getKey(), contentImageOverrideEntity.getOverrideUrl());
            }
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Log.e("ImageOverrideRepo", "Failed to load image overrides", e2);
        }
        return e6a.a;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object resetAllOverrides(int i, @kp6 Continuation<? super e6a> continuation) throws Exception {
        C02911 c02911;
        ContentImageOverrideRepository contentImageOverrideRepository;
        if (continuation instanceof C02911) {
            c02911 = (C02911) continuation;
            int i2 = c02911.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                c02911.label = i2 - Integer.MIN_VALUE;
            } else {
                c02911 = new C02911(continuation);
            }
        }
        Object obj = c02911.result;
        ck1 ck1Var = ck1.a;
        int i3 = c02911.label;
        try {
            if (i3 == 0) {
                s38.b(obj);
                ContentImageOverrideDao contentImageOverrideDao = this.dao;
                c02911.L$0 = this;
                c02911.I$0 = i;
                c02911.label = 1;
                if (contentImageOverrideDao.deleteAllForItem(i, c02911) == ck1Var) {
                    return ck1Var;
                }
                contentImageOverrideRepository = this;
            } else {
                if (i3 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                i = c02911.I$0;
                contentImageOverrideRepository = (ContentImageOverrideRepository) c02911.L$0;
                s38.b(obj);
            }
            ConcurrentHashMap<String, String> concurrentHashMap = contentImageOverrideRepository.overrides;
            ContentImageOverrideEntity.Companion companion = ContentImageOverrideEntity.INSTANCE;
            concurrentHashMap.remove(companion.generateKey(i, ContentImageOverrideEntity.TYPE_POSTER));
            contentImageOverrideRepository.overrides.remove(companion.generateKey(i, ContentImageOverrideEntity.TYPE_BACKDROP));
            gg6<e6a> gg6Var = contentImageOverrideRepository._overrideChanged;
            e6a e6aVar = e6a.a;
            gg6Var.a(e6aVar);
            return e6aVar;
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Log.e("ImageOverrideRepo", "Failed to reset all overrides", e2);
            throw e2;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object resetOverride(int i, @kp6 String str, @kp6 Continuation<? super e6a> continuation) throws Exception {
        C02921 c02921;
        ContentImageOverrideRepository contentImageOverrideRepository;
        if (continuation instanceof C02921) {
            c02921 = (C02921) continuation;
            int i2 = c02921.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                c02921.label = i2 - Integer.MIN_VALUE;
            } else {
                c02921 = new C02921(continuation);
            }
        }
        Object obj = c02921.result;
        ck1 ck1Var = ck1.a;
        int i3 = c02921.label;
        try {
            if (i3 == 0) {
                s38.b(obj);
                ContentImageOverrideDao contentImageOverrideDao = this.dao;
                c02921.L$0 = this;
                c02921.L$1 = str;
                c02921.I$0 = i;
                c02921.label = 1;
                if (contentImageOverrideDao.delete(i, str, c02921) == ck1Var) {
                    return ck1Var;
                }
                contentImageOverrideRepository = this;
            } else {
                if (i3 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                i = c02921.I$0;
                str = (String) c02921.L$1;
                contentImageOverrideRepository = (ContentImageOverrideRepository) c02921.L$0;
                s38.b(obj);
            }
            contentImageOverrideRepository.overrides.remove(ContentImageOverrideEntity.INSTANCE.generateKey(i, str));
            gg6<e6a> gg6Var = contentImageOverrideRepository._overrideChanged;
            e6a e6aVar = e6a.a;
            gg6Var.a(e6aVar);
            return e6aVar;
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Log.e("ImageOverrideRepo", "Failed to reset override", e2);
            throw e2;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0015  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object setOverride(int i, @kp6 String str, @kp6 String str2, @kp6 Continuation<? super e6a> continuation) throws Exception {
        C02931 c02931;
        ContentImageOverrideRepository contentImageOverrideRepository;
        ContentImageOverrideEntity contentImageOverrideEntity;
        String str3;
        if (continuation instanceof C02931) {
            c02931 = (C02931) continuation;
            int i2 = c02931.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                c02931.label = i2 - Integer.MIN_VALUE;
            } else {
                c02931 = new C02931(continuation);
            }
        }
        Object obj = c02931.result;
        ck1 ck1Var = ck1.a;
        int i3 = c02931.label;
        try {
            if (i3 == 0) {
                s38.b(obj);
                ContentImageOverrideEntity contentImageOverrideEntity2 = new ContentImageOverrideEntity(ContentImageOverrideEntity.INSTANCE.generateKey(i, str), i, str, str2, 0L, 16, null);
                ContentImageOverrideDao contentImageOverrideDao = this.dao;
                c02931.L$0 = this;
                c02931.L$1 = str2;
                c02931.L$2 = contentImageOverrideEntity2;
                c02931.label = 1;
                if (contentImageOverrideDao.upsert(contentImageOverrideEntity2, c02931) == ck1Var) {
                    return ck1Var;
                }
                contentImageOverrideRepository = this;
                contentImageOverrideEntity = contentImageOverrideEntity2;
                str3 = str2;
            } else {
                if (i3 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                contentImageOverrideEntity = (ContentImageOverrideEntity) c02931.L$2;
                str3 = (String) c02931.L$1;
                contentImageOverrideRepository = (ContentImageOverrideRepository) c02931.L$0;
                s38.b(obj);
            }
            contentImageOverrideRepository.overrides.put(contentImageOverrideEntity.getKey(), str3);
            gg6<e6a> gg6Var = contentImageOverrideRepository._overrideChanged;
            e6a e6aVar = e6a.a;
            gg6Var.a(e6aVar);
            return e6aVar;
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Log.e("ImageOverrideRepo", "Failed to set override", e2);
            throw e2;
        }
    }
}
