package com.strmr.ps.data.repository;

import androidx.media3.container.MdtaMetadataEntry;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.extractor.AacUtil;
import androidx.media3.extractor.flac.FlacConstants;
import com.strmr.ps.data.local.dao.SyncCheckpointDao;
import com.strmr.ps.data.local.entity.SyncCheckpoint;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.kp6;
import defpackage.pq6;
import defpackage.s38;
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 net.zetetic.database.DatabaseUtils;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\b\b\u0007\u0018\u0000 \u001b2\u00020\u0001:\u0001\u001bB\u0011\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002¢\u0006\u0004\b\u0004\u0010\u0005J\u0018\u0010\t\u001a\u00020\b2\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\t\u0010\nJ6\u0010\u000f\u001a\u00020\u000e2\u0006\u0010\u0007\u001a\u00020\u00062\u0006\u0010\u000b\u001a\u00020\b2\b\b\u0002\u0010\f\u001a\u00020\b2\n\b\u0002\u0010\r\u001a\u0004\u0018\u00010\bH\u0086@¢\u0006\u0004\b\u000f\u0010\u0010J\u0018\u0010\u0011\u001a\u00020\u000e2\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0011\u0010\nJ\u0018\u0010\u0013\u001a\u00020\u00122\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0013\u0010\nJ\u001a\u0010\u0015\u001a\u0004\u0018\u00010\u00142\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0015\u0010\nJ\u0010\u0010\u0016\u001a\u00020\u000eH\u0086@¢\u0006\u0004\b\u0016\u0010\u0017J\u0018\u0010\u0019\u001a\u00020\u000e2\u0006\u0010\u0018\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0019\u0010\nR\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010\u001a¨\u0006\u001c"}, d2 = {"Lcom/strmr/ps/data/repository/SyncProgressManager;", "", "Lcom/strmr/ps/data/local/dao/SyncCheckpointDao;", "syncCheckpointDao", "<init>", "(Lcom/strmr/ps/data/local/dao/SyncCheckpointDao;)V", "", "syncType", "", "getLastPage", "(Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "page", "itemsSynced", "totalItems", "Le6a;", "savePageCheckpoint", "(Ljava/lang/String;IILjava/lang/Integer;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "markComplete", "", "isInProgress", "Lcom/strmr/ps/data/local/entity/SyncCheckpoint;", "getCheckpoint", "clearAllProgress", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "listType", "clearProgressForList", "Lcom/strmr/ps/data/local/dao/SyncCheckpointDao;", "Companion", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public final class SyncProgressManager {

    @kp6
    public static final String SYNC_COLLECTION_MOVIES = "collection_movies";

    @kp6
    public static final String SYNC_COLLECTION_SHOWS = "collection_shows";

    @kp6
    public static final String SYNC_HISTORY_MOVIES = "history_movies";

    @kp6
    public static final String SYNC_HISTORY_SHOWS = "history_shows";

    @kp6
    public static final String SYNC_WATCHLIST_MOVIES = "watchlist_movies";

    @kp6
    public static final String SYNC_WATCHLIST_SHOWS = "watchlist_shows";

    @kp6
    private final SyncCheckpointDao syncCheckpointDao;

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.SyncProgressManager$clearProgressForList$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.SyncProgressManager", f = "SyncProgressManager.kt", i = {0, 2, 4}, l = {90, 91, 94, 95, 98, DatabaseUtils.STATEMENT_OTHER}, m = "clearProgressForList", n = {"this", "this", "this"}, s = {"L$0", "L$0", "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 SyncProgressManager.this.clearProgressForList(null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.SyncProgressManager$getLastPage$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.SyncProgressManager", f = "SyncProgressManager.kt", i = {}, l = {31}, m = "getLastPage", n = {}, s = {})
    public static final class C04151 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C04151(Continuation<? super C04151> 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 SyncProgressManager.this.getLastPage(null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.SyncProgressManager$isInProgress$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.SyncProgressManager", f = "SyncProgressManager.kt", i = {}, l = {MdtaMetadataEntry.TYPE_INDICATOR_INT32}, m = "isInProgress", n = {}, s = {})
    public static final class C04161 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C04161(Continuation<? super C04161> 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 SyncProgressManager.this.isInProgress(null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.SyncProgressManager$savePageCheckpoint$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.SyncProgressManager", f = "SyncProgressManager.kt", i = {0, 0, 0, 0, 0}, l = {FlacConstants.STREAM_INFO_BLOCK_SIZE, NalUnitUtil.H265_NAL_UNIT_TYPE_SUFFIX_SEI, AacUtil.AUDIO_OBJECT_TYPE_AAC_XHE}, m = "savePageCheckpoint", n = {"this", "syncType", "totalItems", "page", "itemsSynced"}, s = {"L$0", "L$1", "L$2", "I$0", "I$1"})
    public static final class C04171 extends ContinuationImpl {
        int I$0;
        int I$1;
        Object L$0;
        Object L$1;
        Object L$2;
        int label;
        /* synthetic */ Object result;

        public C04171(Continuation<? super C04171> 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 SyncProgressManager.this.savePageCheckpoint(null, 0, 0, null, this);
        }
    }

    @Inject
    public SyncProgressManager(@kp6 SyncCheckpointDao syncCheckpointDao) {
        cr4.g(syncCheckpointDao, "syncCheckpointDao");
        this.syncCheckpointDao = syncCheckpointDao;
    }

    public static /* synthetic */ Object savePageCheckpoint$default(SyncProgressManager syncProgressManager, String str, int i, int i2, Integer num, Continuation continuation, int i3, Object obj) {
        if ((i3 & 4) != 0) {
            i2 = 0;
        }
        int i4 = i2;
        if ((i3 & 8) != 0) {
            num = null;
        }
        return syncProgressManager.savePageCheckpoint(str, i, i4, num, continuation);
    }

    @pq6
    public final Object clearAllProgress(@kp6 Continuation<? super e6a> continuation) {
        Object objDeleteAll = this.syncCheckpointDao.deleteAll(continuation);
        return objDeleteAll == ck1.a ? objDeleteAll : e6a.a;
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x0096 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:46:0x00c1 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:56:0x00eb A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:57:0x00ec A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object clearProgressForList(@kp6 String str, @kp6 Continuation<? super e6a> continuation) {
        AnonymousClass1 anonymousClass1;
        SyncProgressManager syncProgressManager;
        SyncProgressManager syncProgressManager2;
        SyncProgressManager syncProgressManager3;
        SyncCheckpointDao syncCheckpointDao;
        SyncCheckpointDao syncCheckpointDao2;
        SyncCheckpointDao syncCheckpointDao3;
        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;
        e6a e6aVar = e6a.a;
        switch (i2) {
            case 0:
                s38.b(obj);
                int iHashCode = str.hashCode();
                if (iHashCode == -1741312354) {
                    if (str.equals("collection")) {
                        SyncCheckpointDao syncCheckpointDao4 = this.syncCheckpointDao;
                        anonymousClass1.L$0 = this;
                        anonymousClass1.label = 3;
                        if (syncCheckpointDao4.delete(SYNC_COLLECTION_MOVIES, anonymousClass1) != ck1Var) {
                            syncProgressManager = this;
                            syncCheckpointDao2 = syncProgressManager.syncCheckpointDao;
                            anonymousClass1.L$0 = null;
                            anonymousClass1.label = 4;
                            if (syncCheckpointDao2.delete(SYNC_COLLECTION_SHOWS, anonymousClass1) == ck1Var) {
                                return e6aVar;
                            }
                        }
                        return ck1Var;
                    }
                    return e6aVar;
                }
                if (iHashCode == -279939603) {
                    if (str.equals("watchlist")) {
                        SyncCheckpointDao syncCheckpointDao5 = this.syncCheckpointDao;
                        anonymousClass1.L$0 = this;
                        anonymousClass1.label = 5;
                        if (syncCheckpointDao5.delete(SYNC_WATCHLIST_MOVIES, anonymousClass1) != ck1Var) {
                            syncProgressManager2 = this;
                            syncCheckpointDao3 = syncProgressManager2.syncCheckpointDao;
                            anonymousClass1.L$0 = null;
                            anonymousClass1.label = 6;
                            if (syncCheckpointDao3.delete(SYNC_WATCHLIST_SHOWS, anonymousClass1) == ck1Var) {
                                return e6aVar;
                            }
                        }
                        return ck1Var;
                    }
                    return e6aVar;
                }
                if (iHashCode == 926934164 && str.equals("history")) {
                    SyncCheckpointDao syncCheckpointDao6 = this.syncCheckpointDao;
                    anonymousClass1.L$0 = this;
                    anonymousClass1.label = 1;
                    if (syncCheckpointDao6.delete(SYNC_HISTORY_MOVIES, anonymousClass1) != ck1Var) {
                        syncProgressManager3 = this;
                        syncCheckpointDao = syncProgressManager3.syncCheckpointDao;
                        anonymousClass1.L$0 = null;
                        anonymousClass1.label = 2;
                        if (syncCheckpointDao.delete(SYNC_HISTORY_SHOWS, anonymousClass1) != ck1Var) {
                            return e6aVar;
                        }
                    }
                    return ck1Var;
                }
                return e6aVar;
            case 1:
                syncProgressManager3 = (SyncProgressManager) anonymousClass1.L$0;
                s38.b(obj);
                syncCheckpointDao = syncProgressManager3.syncCheckpointDao;
                anonymousClass1.L$0 = null;
                anonymousClass1.label = 2;
                if (syncCheckpointDao.delete(SYNC_HISTORY_SHOWS, anonymousClass1) != ck1Var) {
                    return ck1Var;
                }
                break;
            case 2:
                s38.b(obj);
                return e6aVar;
            case 3:
                syncProgressManager = (SyncProgressManager) anonymousClass1.L$0;
                s38.b(obj);
                syncCheckpointDao2 = syncProgressManager.syncCheckpointDao;
                anonymousClass1.L$0 = null;
                anonymousClass1.label = 4;
                if (syncCheckpointDao2.delete(SYNC_COLLECTION_SHOWS, anonymousClass1) == ck1Var) {
                }
                break;
            case 4:
                s38.b(obj);
                return e6aVar;
            case 5:
                syncProgressManager2 = (SyncProgressManager) anonymousClass1.L$0;
                s38.b(obj);
                syncCheckpointDao3 = syncProgressManager2.syncCheckpointDao;
                anonymousClass1.L$0 = null;
                anonymousClass1.label = 6;
                if (syncCheckpointDao3.delete(SYNC_WATCHLIST_SHOWS, anonymousClass1) == ck1Var) {
                }
                break;
            case 6:
                s38.b(obj);
                return e6aVar;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }

    @pq6
    public final Object getCheckpoint(@kp6 String str, @kp6 Continuation<? super SyncCheckpoint> continuation) {
        return this.syncCheckpointDao.getCheckpoint(str, continuation);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object getLastPage(@kp6 String str, @kp6 Continuation<? super Integer> continuation) {
        C04151 c04151;
        if (continuation instanceof C04151) {
            c04151 = (C04151) continuation;
            int i = c04151.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c04151.label = i - Integer.MIN_VALUE;
            } else {
                c04151 = new C04151(continuation);
            }
        }
        Object lastPage = c04151.result;
        ck1 ck1Var = ck1.a;
        int i2 = c04151.label;
        if (i2 == 0) {
            s38.b(lastPage);
            SyncCheckpointDao syncCheckpointDao = this.syncCheckpointDao;
            c04151.label = 1;
            lastPage = syncCheckpointDao.getLastPage(str, c04151);
            if (lastPage == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(lastPage);
        }
        Integer num = (Integer) lastPage;
        return Boxing.boxInt(num != null ? num.intValue() : 0);
    }

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

    @pq6
    public final Object markComplete(@kp6 String str, @kp6 Continuation<? super e6a> continuation) {
        Object objMarkComplete$default = SyncCheckpointDao.DefaultImpls.markComplete$default(this.syncCheckpointDao, str, 0L, continuation, 2, null);
        return objMarkComplete$default == ck1.a ? objMarkComplete$default : e6a.a;
    }

    /* JADX WARN: Removed duplicated region for block: B:8:0x001a  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object savePageCheckpoint(@kp6 String str, int i, int i2, @pq6 Integer num, @kp6 Continuation<? super e6a> continuation) {
        C04171 c04171;
        String str2;
        Integer num2;
        int i3;
        int i4;
        SyncProgressManager syncProgressManager;
        if (continuation instanceof C04171) {
            c04171 = (C04171) continuation;
            int i5 = c04171.label;
            if ((i5 & Integer.MIN_VALUE) != 0) {
                c04171.label = i5 - Integer.MIN_VALUE;
            } else {
                c04171 = new C04171(continuation);
            }
        }
        C04171 c041712 = c04171;
        Object checkpoint = c041712.result;
        ck1 ck1Var = ck1.a;
        int i6 = c041712.label;
        e6a e6aVar = e6a.a;
        if (i6 == 0) {
            s38.b(checkpoint);
            SyncCheckpointDao syncCheckpointDao = this.syncCheckpointDao;
            c041712.L$0 = this;
            c041712.L$1 = str;
            c041712.L$2 = num;
            c041712.I$0 = i;
            c041712.I$1 = i2;
            c041712.label = 1;
            checkpoint = syncCheckpointDao.getCheckpoint(str, c041712);
            if (checkpoint != ck1Var) {
                str2 = str;
                num2 = num;
                i3 = i;
                i4 = i2;
                syncProgressManager = this;
            }
            return ck1Var;
        }
        if (i6 != 1) {
            if (i6 == 2) {
                s38.b(checkpoint);
                return e6aVar;
            }
            if (i6 != 3) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(checkpoint);
            return e6aVar;
        }
        int i7 = c041712.I$1;
        int i8 = c041712.I$0;
        Integer num3 = (Integer) c041712.L$2;
        String str3 = (String) c041712.L$1;
        syncProgressManager = (SyncProgressManager) c041712.L$0;
        s38.b(checkpoint);
        i4 = i7;
        i3 = i8;
        num2 = num3;
        str2 = str3;
        if (((SyncCheckpoint) checkpoint) != null) {
            SyncCheckpointDao syncCheckpointDao2 = syncProgressManager.syncCheckpointDao;
            c041712.L$0 = null;
            c041712.L$1 = null;
            c041712.L$2 = null;
            c041712.label = 2;
            if (SyncCheckpointDao.DefaultImpls.updateProgress$default(syncCheckpointDao2, str2, i3, i4, 0L, c041712, 8, null) != ck1Var) {
                return e6aVar;
            }
        } else {
            SyncCheckpointDao syncCheckpointDao3 = syncProgressManager.syncCheckpointDao;
            SyncCheckpoint syncCheckpoint = new SyncCheckpoint(str2, i3, true, i4, num2, System.currentTimeMillis(), System.currentTimeMillis());
            c041712.L$0 = null;
            c041712.L$1 = null;
            c041712.L$2 = null;
            c041712.label = 3;
            if (syncCheckpointDao3.upsert(syncCheckpoint, c041712) != ck1Var) {
                return e6aVar;
            }
        }
        return ck1Var;
    }
}
