package O1;

import B0.C0016c;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.data.local.AppDatabase_Impl;
import d5.AbstractC0844a;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: loaded from: classes.dex */
public final class T {

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static final String[] f4998l = {"INSERT", "UPDATE", "DELETE"};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final AppDatabase_Impl f4999a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final LinkedHashMap f5000b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final LinkedHashMap f5001c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final boolean f5002d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final F5.n f5003e;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final String[] f5005g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final C0016c f5006h;
    public final r i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final AtomicBoolean f5007j = new AtomicBoolean(false);

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public O6.a f5008k = new C5.b(6);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final LinkedHashMap f5004f = new LinkedHashMap();

    public T(AppDatabase_Impl appDatabase_Impl, LinkedHashMap linkedHashMap, LinkedHashMap linkedHashMap2, String[] strArr, boolean z8, F5.n nVar) {
        String lowerCase;
        this.f4999a = appDatabase_Impl;
        this.f5000b = linkedHashMap;
        this.f5001c = linkedHashMap2;
        this.f5002d = z8;
        this.f5003e = nVar;
        int length = strArr.length;
        String[] strArr2 = new String[length];
        for (int i = 0; i < length; i++) {
            String str = strArr[i];
            Locale locale = Locale.ROOT;
            String lowerCase2 = str.toLowerCase(locale);
            P6.g.d(lowerCase2, "toLowerCase(...)");
            this.f5004f.put(lowerCase2, Integer.valueOf(i));
            String str2 = (String) this.f5000b.get(strArr[i]);
            if (str2 != null) {
                lowerCase = str2.toLowerCase(locale);
                P6.g.d(lowerCase, "toLowerCase(...)");
            } else {
                lowerCase = null;
            }
            if (lowerCase != null) {
                lowerCase2 = lowerCase;
            }
            strArr2[i] = lowerCase2;
        }
        this.f5005g = strArr2;
        for (Map.Entry entry : this.f5000b.entrySet()) {
            String str3 = (String) entry.getValue();
            Locale locale2 = Locale.ROOT;
            String lowerCase3 = str3.toLowerCase(locale2);
            P6.g.d(lowerCase3, "toLowerCase(...)");
            if (this.f5004f.containsKey(lowerCase3)) {
                String lowerCase4 = ((String) entry.getKey()).toLowerCase(locale2);
                P6.g.d(lowerCase4, "toLowerCase(...)");
                LinkedHashMap linkedHashMap3 = this.f5004f;
                linkedHashMap3.put(lowerCase4, B6.w.k0(linkedHashMap3, lowerCase3));
            }
        }
        this.f5006h = new C0016c(this.f5005g.length);
        this.i = new r(this.f5005g.length);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object a(T t6, InterfaceC0243t interfaceC0243t, G6.c cVar) throws Throwable {
        I i;
        t6.getClass();
        if (cVar instanceof I) {
            i = (I) cVar;
            int i5 = i.f4949w;
            if ((i5 & Integer.MIN_VALUE) != 0) {
                i.f4949w = i5 - Integer.MIN_VALUE;
            } else {
                i = new I(t6, cVar);
            }
        }
        Object objA = i.f4947u;
        F6.a aVar = F6.a.f2580q;
        int i8 = i.f4949w;
        if (i8 == 0) {
            C1.N(objA);
            M5.b bVar = new M5.b(4);
            i.f4946t = interfaceC0243t;
            i.f4949w = 1;
            objA = interfaceC0243t.a("SELECT * FROM room_table_modification_log WHERE invalidated = 1", bVar, i);
            if (objA != aVar) {
            }
            return aVar;
        }
        if (i8 != 1) {
            if (i8 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            Set set = (Set) i.f4946t;
            C1.N(objA);
            return set;
        }
        interfaceC0243t = (InterfaceC0243t) i.f4946t;
        C1.N(objA);
        Set set2 = (Set) objA;
        if (!set2.isEmpty()) {
            i.f4946t = set2;
            i.f4949w = 2;
            if (s7.l.j(interfaceC0243t, "UPDATE room_table_modification_log SET invalidated = 0 WHERE invalidated = 1", i) == aVar) {
                return aVar;
            }
        }
        return set2;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object b(T t6, G6.c cVar) throws Throwable {
        J j8;
        C0225a c0225a;
        Throwable th;
        C0225a c0225a2;
        t6.getClass();
        if (cVar instanceof J) {
            j8 = (J) cVar;
            int i = j8.f4954x;
            if ((i & Integer.MIN_VALUE) != 0) {
                j8.f4954x = i - Integer.MIN_VALUE;
            } else {
                j8 = new J(t6, cVar);
            }
        }
        Object objI = j8.f4952v;
        F6.a aVar = F6.a.f2580q;
        int i5 = j8.f4954x;
        if (i5 == 0) {
            C1.N(objI);
            AppDatabase_Impl appDatabase_Impl = t6.f4999a;
            c0225a = appDatabase_Impl.f4920g;
            boolean zF = c0225a.f();
            B6.v vVar = B6.v.f1034q;
            if (!zF) {
                return vVar;
            }
            try {
                if (!t6.f5007j.compareAndSet(true, false)) {
                    c0225a.v();
                    return vVar;
                }
                if (!((Boolean) t6.f5008k.a()).booleanValue()) {
                    c0225a.v();
                    return vVar;
                }
                L l8 = new L(t6, null);
                j8.f4950t = t6;
                j8.f4951u = c0225a;
                j8.f4954x = 1;
                objI = appDatabase_Impl.i(false, l8, j8);
                if (objI == aVar) {
                    return aVar;
                }
            } catch (Throwable th2) {
                th = th2;
                c0225a2 = c0225a;
                c0225a2.v();
                throw th;
            }
        } else {
            if (i5 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            c0225a2 = j8.f4951u;
            T t8 = j8.f4950t;
            try {
                C1.N(objI);
                c0225a = c0225a2;
                t6 = t8;
            } catch (Throwable th3) {
                th = th3;
                c0225a2.v();
                throw th;
            }
        }
        Set set = (Set) objI;
        if (!set.isEmpty()) {
            t6.i.b(set);
            t6.f5003e.b(set);
        }
        c0225a.v();
        return set;
    }

    /* JADX WARN: Code restructure failed: missing block: B:17:0x0070, code lost:
    
        if (r15 == r1) goto L27;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x00e5, code lost:
    
        if (r15 == r1) goto L27;
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x00e7, code lost:
    
        return r1;
     */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0083  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00ea  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:26:0x00e5 -> B:28:0x00e8). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object c(T t6, H h8, int i, G6.c cVar) throws Throwable {
        N n8;
        InterfaceC0243t interfaceC0243t;
        String[] strArr;
        T t8;
        int i5;
        InterfaceC0243t interfaceC0243t2;
        int i8;
        String str;
        t6.getClass();
        if (cVar instanceof N) {
            n8 = (N) cVar;
            int i9 = n8.f4966C;
            if ((i9 & Integer.MIN_VALUE) != 0) {
                n8.f4966C = i9 - Integer.MIN_VALUE;
            } else {
                n8 = new N(t6, cVar);
            }
        }
        Object obj = n8.f4964A;
        F6.a aVar = F6.a.f2580q;
        int i10 = n8.f4966C;
        if (i10 == 0) {
            C1.N(obj);
            n8.f4967t = t6;
            n8.f4968u = h8;
            n8.f4971x = i;
            n8.f4966C = 1;
            Object objJ = s7.l.j(h8, "INSERT OR IGNORE INTO room_table_modification_log VALUES(" + i + ", 0)", n8);
            interfaceC0243t = h8;
        } else if (i10 == 1) {
            i = n8.f4971x;
            InterfaceC0243t interfaceC0243t3 = n8.f4968u;
            t6 = n8.f4967t;
            C1.N(obj);
            interfaceC0243t = interfaceC0243t3;
        } else {
            if (i10 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i5 = n8.f4973z;
            i8 = n8.f4972y;
            i = n8.f4971x;
            strArr = n8.f4970w;
            str = n8.f4969v;
            InterfaceC0243t interfaceC0243t4 = n8.f4968u;
            t8 = n8.f4967t;
            C1.N(obj);
            InterfaceC0243t interfaceC0243t5 = interfaceC0243t4;
            i8++;
            interfaceC0243t2 = interfaceC0243t5;
            if (i8 < i5) {
                return A6.n.f457a;
            }
            String str2 = strArr[i8];
            String str3 = t8.f5002d ? "TEMP" : "";
            StringBuilder sb = new StringBuilder("CREATE ");
            sb.append(str3);
            sb.append(" TRIGGER IF NOT EXISTS `");
            sb.append("room_table_modification_trigger_" + str + '_' + str2);
            sb.append("` AFTER ");
            sb.append(str2);
            sb.append(" ON `");
            sb.append(str);
            sb.append("` BEGIN UPDATE room_table_modification_log SET invalidated = 1 WHERE table_id = ");
            String strN = AbstractC0844a.n(sb, i, " AND invalidated = 0; END");
            n8.f4967t = t8;
            n8.f4968u = interfaceC0243t2;
            n8.f4969v = str;
            n8.f4970w = strArr;
            n8.f4971x = i;
            n8.f4972y = i8;
            n8.f4973z = i5;
            n8.f4966C = 2;
            Object objJ2 = s7.l.j(interfaceC0243t2, strN, n8);
            interfaceC0243t5 = interfaceC0243t2;
        }
        String str4 = t6.f5005g[i];
        strArr = f4998l;
        t8 = t6;
        i5 = 3;
        interfaceC0243t2 = interfaceC0243t;
        i8 = 0;
        str = str4;
        if (i8 < i5) {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x0052  */
    /* JADX WARN: Removed duplicated region for block: B:20:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:17:0x008d -> B:19:0x0090). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object d(T t6, H h8, int i, G6.c cVar) throws Throwable {
        O o8;
        String str;
        int i5;
        InterfaceC0243t interfaceC0243t;
        int i8;
        String[] strArr;
        t6.getClass();
        if (cVar instanceof O) {
            o8 = (O) cVar;
            int i9 = o8.f4974A;
            if ((i9 & Integer.MIN_VALUE) != 0) {
                o8.f4974A = i9 - Integer.MIN_VALUE;
            } else {
                o8 = new O(t6, cVar);
            }
        }
        Object obj = o8.f4980y;
        F6.a aVar = F6.a.f2580q;
        int i10 = o8.f4974A;
        if (i10 == 0) {
            C1.N(obj);
            str = t6.f5005g[i];
            i5 = 3;
            interfaceC0243t = h8;
            i8 = 0;
            strArr = f4998l;
            if (i8 < i5) {
            }
        } else {
            if (i10 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i5 = o8.f4979x;
            i8 = o8.f4978w;
            String[] strArr2 = o8.f4977v;
            str = o8.f4976u;
            InterfaceC0243t interfaceC0243t2 = o8.f4975t;
            C1.N(obj);
            strArr = strArr2;
            interfaceC0243t = interfaceC0243t2;
            i8++;
            if (i8 < i5) {
                String str2 = "DROP TRIGGER IF EXISTS `" + ("room_table_modification_trigger_" + str + '_' + strArr[i8]) + '`';
                o8.f4975t = interfaceC0243t;
                o8.f4976u = str;
                o8.f4977v = strArr;
                o8.f4978w = i8;
                o8.f4979x = i5;
                o8.f4974A = 1;
                if (s7.l.j(interfaceC0243t, str2, o8) == aVar) {
                    return aVar;
                }
                i8++;
                if (i8 < i5) {
                    return A6.n.f457a;
                }
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object e(G6.c cVar) throws Throwable {
        P p3;
        C0225a c0225a;
        if (cVar instanceof P) {
            p3 = (P) cVar;
            int i = p3.f4985w;
            if ((i & Integer.MIN_VALUE) != 0) {
                p3.f4985w = i - Integer.MIN_VALUE;
            } else {
                p3 = new P(this, cVar);
            }
        }
        Object obj = p3.f4983u;
        F6.a aVar = F6.a.f2580q;
        int i5 = p3.f4985w;
        if (i5 == 0) {
            C1.N(obj);
            AppDatabase_Impl appDatabase_Impl = this.f4999a;
            C0225a c0225a2 = appDatabase_Impl.f4920g;
            if (c0225a2.f()) {
                try {
                    S s8 = new S(this, null);
                    p3.f4982t = c0225a2;
                    p3.f4985w = 1;
                    if (appDatabase_Impl.i(false, s8, p3) == aVar) {
                        return aVar;
                    }
                    c0225a = c0225a2;
                    c0225a.v();
                } catch (Throwable th) {
                    th = th;
                    c0225a = c0225a2;
                    c0225a.v();
                    throw th;
                }
            }
        } else {
            if (i5 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            c0225a = p3.f4982t;
            try {
                C1.N(obj);
                c0225a.v();
            } catch (Throwable th2) {
                th = th2;
                c0225a.v();
                throw th;
            }
        }
        return A6.n.f457a;
    }
}
