package com.strmr.ps.data.repository;

import android.util.Log;
import com.strmr.ps.data.local.dao.InstalledAddonDao;
import com.strmr.ps.data.local.dao.RowConfigDao;
import com.strmr.ps.data.supabase.DeviceManager;
import com.strmr.ps.data.supabase.SettingsSyncManager;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.kq;
import defpackage.q38;
import defpackage.s38;
import java.util.List;
import java.util.concurrent.ExecutorService;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "Lq38;", "Le6a;", "<anonymous>", "(Lak1;)Lq38;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.repository.AddonRepository$uninstallAddon$2", f = "AddonRepository.kt", i = {1, 2, 3, 3, 5}, l = {793, 794, 796, 797, 802, 813, 819}, m = "invokeSuspend", n = {"catalogRowsDeleted", "catalogRowsDeleted", "catalogRowsDeleted", "searchRowsDeleted", "accessToken"}, s = {"I$0", "I$0", "I$0", "I$1", "L$0"})
public final class AddonRepository$uninstallAddon$2 extends SuspendLambda implements gr3<ak1, Continuation<? super q38<? extends e6a>>, Object> {
    final /* synthetic */ String $instanceId;
    int I$0;
    int I$1;
    Object L$0;
    int label;
    final /* synthetic */ AddonRepository this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public AddonRepository$uninstallAddon$2(AddonRepository addonRepository, String str, Continuation<? super AddonRepository$uninstallAddon$2> continuation) {
        super(2, continuation);
        this.this$0 = addonRepository;
        this.$instanceId = str;
    }

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

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

    /* JADX WARN: Code restructure failed: missing block: B:53:0x015d, code lost:
    
        if (r10.l(r9) != r1) goto L55;
     */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0098  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x009a  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00bd  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00bf A[Catch: Exception -> 0x0032, PHI: r2 r10
      0x00bf: PHI (r2v10 int) = (r2v8 int), (r2v11 int) binds: [B:36:0x00bb, B:21:0x003c] A[DONT_GENERATE, DONT_INLINE]
      0x00bf: PHI (r10v24 java.lang.Object) = (r10v23 java.lang.Object), (r10v0 java.lang.Object) binds: [B:36:0x00bb, B:21:0x003c] A[DONT_GENERATE, DONT_INLINE], TryCatch #2 {Exception -> 0x0032, blocks: (B:58:0x0171, B:51:0x0142, B:15:0x002d, B:44:0x00fd, B:18:0x0035, B:41:0x00eb, B:21:0x003c, B:38:0x00bf, B:24:0x0043, B:35:0x009b, B:25:0x0047, B:31:0x0070, B:28:0x004e, B:57:0x0168, B:6:0x0019, B:55:0x0160, B:52:0x0147, B:11:0x0025, B:49:0x013a, B:46:0x0122), top: B:63:0x000e, inners: #0, #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00e9  */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00eb A[Catch: Exception -> 0x0032, TryCatch #2 {Exception -> 0x0032, blocks: (B:58:0x0171, B:51:0x0142, B:15:0x002d, B:44:0x00fd, B:18:0x0035, B:41:0x00eb, B:21:0x003c, B:38:0x00bf, B:24:0x0043, B:35:0x009b, B:25:0x0047, B:31:0x0070, B:28:0x004e, B:57:0x0168, B:6:0x0019, B:55:0x0160, B:52:0x0147, B:11:0x0025, B:49:0x013a, B:46:0x0122), top: B:63:0x000e, inners: #0, #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00fc  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00fd A[Catch: Exception -> 0x0032, TRY_LEAVE, TryCatch #2 {Exception -> 0x0032, blocks: (B:58:0x0171, B:51:0x0142, B:15:0x002d, B:44:0x00fd, B:18:0x0035, B:41:0x00eb, B:21:0x003c, B:38:0x00bf, B:24:0x0043, B:35:0x009b, B:25:0x0047, B:31:0x0070, B:28:0x004e, B:57:0x0168, B:6:0x0019, B:55:0x0160, B:52:0x0147, B:11:0x0025, B:49:0x013a, B:46:0x0122), top: B:63:0x000e, inners: #0, #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0122 A[Catch: Exception -> 0x002a, TRY_ENTER, TryCatch #1 {Exception -> 0x002a, blocks: (B:11:0x0025, B:49:0x013a, B:46:0x0122), top: B:63:0x000e, outer: #2 }] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Object objA;
        RowConfigDao rowConfigDao;
        String str;
        int i;
        RowConfigDao rowConfigDao2;
        String str2;
        InstalledAddonDao installedAddonDao;
        String str3;
        String strE;
        ck1 ck1Var = ck1.a;
        try {
            try {
                try {
                } catch (Exception e) {
                    Boxing.boxInt(Log.w("AddonRepository", "Row cleanup cloud sync failed (persists locally)", e));
                }
            } catch (Exception e2) {
                Log.w("AddonRepository", "Addon deletion cloud sync failed (persists locally)", e2);
            }
        } catch (Exception e3) {
            Log.e("AddonRepository", "Failed to uninstall addon: " + this.$instanceId, e3);
            objA = s38.a(e3);
        }
        switch (this.label) {
            case 0:
                s38.b(obj);
                RowConfigDao rowConfigDao3 = this.this$0.rowConfigDao;
                String str4 = "addon_catalog:" + this.$instanceId + ":";
                this.label = 1;
                obj = rowConfigDao3.getRowsByDataSourcePrefix(str4, this);
                if (obj != ck1Var) {
                    int size = ((List) obj).size();
                    rowConfigDao = this.this$0.rowConfigDao;
                    str = "addon_catalog:" + this.$instanceId + ":";
                    this.I$0 = size;
                    this.label = 2;
                    if (rowConfigDao.deleteRowsByDataSourcePrefix(str, this) == ck1Var) {
                        i = size;
                        RowConfigDao rowConfigDao4 = this.this$0.rowConfigDao;
                        String str5 = "addon_search:" + this.$instanceId + ":";
                        this.I$0 = i;
                        this.label = 3;
                        obj = rowConfigDao4.getRowsByDataSourcePrefix(str5, this);
                        if (obj == ck1Var) {
                            int size2 = ((List) obj).size();
                            rowConfigDao2 = this.this$0.rowConfigDao;
                            str2 = "addon_search:" + this.$instanceId + ":";
                            this.I$0 = i;
                            this.I$1 = size2;
                            this.label = 4;
                            if (rowConfigDao2.deleteRowsByDataSourcePrefix(str2, this) == ck1Var) {
                                installedAddonDao = this.this$0.addonDao;
                                str3 = this.$instanceId;
                                this.label = 5;
                                if (installedAddonDao.deleteAddonByInstanceId(str3, this) == ck1Var) {
                                    ExecutorService executorService = kq.a;
                                    kq.h("AddonRepository", "Uninstalled addon: " + this.$instanceId);
                                    strE = ((DeviceManager) this.this$0.deviceManager.get()).e();
                                    if (strE != null) {
                                        SettingsSyncManager settingsSyncManager = (SettingsSyncManager) this.this$0.settingsSyncManager.get();
                                        this.L$0 = strE;
                                        this.label = 6;
                                        if (settingsSyncManager.h(this) == ck1Var) {
                                        }
                                        ExecutorService executorService2 = kq.a;
                                        kq.h("AddonRepository", "Addon deletion synced to cloud");
                                        SettingsSyncManager settingsSyncManager2 = (SettingsSyncManager) this.this$0.settingsSyncManager.get();
                                        this.L$0 = null;
                                        this.label = 7;
                                        break;
                                    }
                                    objA = e6a.a;
                                    return new q38(objA);
                                }
                            }
                        }
                    }
                }
                return ck1Var;
            case 1:
                s38.b(obj);
                int size3 = ((List) obj).size();
                rowConfigDao = this.this$0.rowConfigDao;
                str = "addon_catalog:" + this.$instanceId + ":";
                this.I$0 = size3;
                this.label = 2;
                if (rowConfigDao.deleteRowsByDataSourcePrefix(str, this) == ck1Var) {
                }
                break;
            case 2:
                i = this.I$0;
                s38.b(obj);
                RowConfigDao rowConfigDao42 = this.this$0.rowConfigDao;
                String str52 = "addon_search:" + this.$instanceId + ":";
                this.I$0 = i;
                this.label = 3;
                obj = rowConfigDao42.getRowsByDataSourcePrefix(str52, this);
                if (obj == ck1Var) {
                }
                return ck1Var;
            case 3:
                i = this.I$0;
                s38.b(obj);
                int size22 = ((List) obj).size();
                rowConfigDao2 = this.this$0.rowConfigDao;
                str2 = "addon_search:" + this.$instanceId + ":";
                this.I$0 = i;
                this.I$1 = size22;
                this.label = 4;
                if (rowConfigDao2.deleteRowsByDataSourcePrefix(str2, this) == ck1Var) {
                }
                return ck1Var;
            case 4:
                s38.b(obj);
                installedAddonDao = this.this$0.addonDao;
                str3 = this.$instanceId;
                this.label = 5;
                if (installedAddonDao.deleteAddonByInstanceId(str3, this) == ck1Var) {
                }
                return ck1Var;
            case 5:
                s38.b(obj);
                ExecutorService executorService3 = kq.a;
                kq.h("AddonRepository", "Uninstalled addon: " + this.$instanceId);
                strE = ((DeviceManager) this.this$0.deviceManager.get()).e();
                if (strE != null) {
                }
                objA = e6a.a;
                return new q38(objA);
            case 6:
                s38.b(obj);
                ExecutorService executorService22 = kq.a;
                kq.h("AddonRepository", "Addon deletion synced to cloud");
                SettingsSyncManager settingsSyncManager22 = (SettingsSyncManager) this.this$0.settingsSyncManager.get();
                this.L$0 = null;
                this.label = 7;
                break;
            case 7:
                s38.b(obj);
                ExecutorService executorService4 = kq.a;
                kq.h("AddonRepository", "Row cleanup synced to cloud");
                objA = e6a.a;
                return new q38(objA);
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }
}
