package defpackage;

import android.app.ActivityManager;
import android.content.Context;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;

/* renamed from: ˌᵕᵮ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1605 {

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public InterfaceC2262 f6364;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final String f6368;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final C5563 f6371;

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public boolean f6372;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public boolean f6373;

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public InterfaceC0805 f6374;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final Context f6375;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final ArrayList f6379 = new ArrayList();

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final ArrayList f6363 = new ArrayList();

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public int f6367 = 1;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final long f6366 = -1;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final C4752 f6378 = new C4752(3);

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final LinkedHashSet f6369 = new LinkedHashSet();

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final LinkedHashSet f6376 = new LinkedHashSet();

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final ArrayList f6377 = new ArrayList();

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public boolean f6365 = true;

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public final boolean f6370 = true;

    public C1605(Context context, Class cls, String str) {
        this.f6371 = AbstractC1641.m4709(cls);
        this.f6375 = context;
        this.f6368 = str;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m4592(AbstractC3980... abstractC3980Arr) {
        for (AbstractC3980 abstractC3980 : abstractC3980Arr) {
            Integer numValueOf = Integer.valueOf(abstractC3980.f15017);
            LinkedHashSet linkedHashSet = this.f6376;
            linkedHashSet.add(numValueOf);
            linkedHashSet.add(Integer.valueOf(abstractC3980.f15018));
        }
        AbstractC3980[] abstractC3980Arr2 = (AbstractC3980[]) Arrays.copyOf(abstractC3980Arr, abstractC3980Arr.length);
        C4752 c4752 = this.f6378;
        c4752.getClass();
        for (AbstractC3980 abstractC39802 : abstractC3980Arr2) {
            c4752.m10034(abstractC39802);
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final AbstractC5069 m4593() {
        int i;
        String name;
        Executor executorC0374;
        boolean zContainsKey;
        LinkedHashSet linkedHashSet = this.f6376;
        boolean zIsEmpty = linkedHashSet.isEmpty();
        LinkedHashSet linkedHashSet2 = this.f6369;
        if (!zIsEmpty) {
            Iterator it = linkedHashSet.iterator();
            while (it.hasNext()) {
                int iIntValue = ((Number) it.next()).intValue();
                if (linkedHashSet2.contains(Integer.valueOf(iIntValue))) {
                    ᵹˉᵞ.ᵸˑ(AbstractC2990.m7313(iIntValue, "Inconsistency detected. A Migration was supplied to addMigration() that has a start or end version equal to a start version supplied to fallbackToDestructiveMigrationFrom(). Start version is: "));
                    return null;
                }
            }
        }
        if (this.f6374 == null) {
            this.f6374 = new C0977();
        }
        int i2 = this.f6367;
        if (i2 == 0) {
            throw null;
        }
        if (i2 == 1) {
            Context context = this.f6375;
            Object systemService = context != null ? context.getSystemService("activity") : null;
            ActivityManager activityManager = systemService instanceof ActivityManager ? (ActivityManager) systemService : null;
            if (activityManager == null || !activityManager.isLowRamDevice()) {
                i2 = 3;
                i = i2;
            } else {
                i = 2;
            }
        } else {
            i = i2;
        }
        if (this.f6366 > 0) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Required value was null.");
            return null;
        }
        InterfaceC0939 c1832 = C3207.f12129;
        String str = this.f6368;
        if (str != null && i != 2) {
            c1832 = new C1832();
        }
        InterfaceC0939 interfaceC0939 = c1832;
        boolean z = this.f6365;
        boolean z2 = this.f6373;
        boolean z3 = this.f6372;
        InterfaceC0805 interfaceC0805 = this.f6374;
        if (interfaceC0805 == null) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Required value was null.");
            return null;
        }
        InterfaceC2262 interfaceC2262 = this.f6364;
        if (interfaceC2262 == null) {
            C1980 c1980 = AbstractC4021.f15114;
            interfaceC2262 = ExecutorC0120.f1436;
        }
        InterfaceC2262 interfaceC22622 = interfaceC2262;
        Context context2 = this.f6375;
        C4752 c4752 = this.f6378;
        ArrayList arrayList = this.f6379;
        ArrayList arrayList2 = this.f6363;
        ArrayList arrayList3 = this.f6377;
        C5001 c5001 = new C5001(context2, str, c4752, arrayList, i, z, z2, linkedHashSet2, arrayList2, arrayList3, z3, interfaceC0805, interfaceC22622, interfaceC0939);
        c5001.f18573 = this.f6370;
        Class cls = this.f6371.f20859;
        Package r0 = cls.getPackage();
        if (r0 == null || (name = r0.getName()) == null) {
            name = "";
        }
        String canonicalName = cls.getCanonicalName();
        if (name.length() != 0) {
            canonicalName = canonicalName.substring(name.length() + 1);
        }
        String strConcat = canonicalName.replace('.', '_').concat("_Impl");
        try {
            AbstractC5069 abstractC5069 = (AbstractC5069) Class.forName(name.length() == 0 ? strConcat : name + "." + strConcat, true, cls.getClassLoader()).getDeclaredConstructor(null).newInstance(null);
            abstractC5069.f18944 = c5001.f18573;
            AbstractC1741 abstractC1741M10533 = abstractC5069.m10533();
            int i3 = abstractC1741M10533.f6950;
            abstractC5069.f18941 = new C0499(c5001, abstractC1741M10533, new ᵽᵢᵚˋ(2, abstractC5069, ˁˈᵸ.class, "withTransactionContext", "withTransactionContext(Landroidx/room3/RoomDatabase;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", 1, 0, 5));
            abstractC5069.f18945 = abstractC5069.m10530();
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            Set setM10528 = abstractC5069.m10528();
            int size = arrayList3.size();
            boolean[] zArr = new boolean[size];
            Iterator it2 = setM10528.iterator();
            while (true) {
                int i4 = -1;
                if (!it2.hasNext()) {
                    int size2 = arrayList3.size() - 1;
                    if (size2 >= 0) {
                        while (true) {
                            int i5 = size2 - 1;
                            if (size2 >= size || !zArr[size2]) {
                                break;
                            }
                            if (i5 < 0) {
                                break;
                            }
                            size2 = i5;
                        }
                        ᵹˉᵞ.ˌᵜᵹᵩ("Unexpected auto migration specs found. Annotate AutoMigrationSpec implementation with @ProvidedAutoMigrationSpec annotation or remove this spec from the builder.");
                        return null;
                    }
                    for (AbstractC3980 abstractC3980 : abstractC5069.m10532()) {
                        int i6 = abstractC3980.f15017;
                        int i7 = abstractC3980.f15018;
                        LinkedHashMap linkedHashMap2 = c4752.f17615;
                        if (linkedHashMap2.containsKey(Integer.valueOf(i6))) {
                            Map map = (Map) linkedHashMap2.get(Integer.valueOf(i6));
                            if (map == null) {
                                map = C1859.f7545;
                            }
                            zContainsKey = map.containsKey(Integer.valueOf(i7));
                        } else {
                            zContainsKey = false;
                        }
                        if (!zContainsKey) {
                            c4752.m10034(abstractC3980);
                        }
                    }
                    Map mapM10529 = abstractC5069.m10529();
                    List list = c5001.f18571;
                    boolean[] zArr2 = new boolean[list.size()];
                    for (Map.Entry entry : mapM10529.entrySet()) {
                        C5563 c5563 = (C5563) entry.getKey();
                        for (C5563 c55632 : (List) entry.getValue()) {
                            int size3 = list.size() - 1;
                            if (size3 >= 0) {
                                while (true) {
                                    int i8 = size3 - 1;
                                    if (c55632.m11197(list.get(size3))) {
                                        zArr2[size3] = true;
                                        break;
                                    }
                                    if (i8 < 0) {
                                        break;
                                    }
                                    size3 = i8;
                                }
                                size3 = -1;
                            } else {
                                size3 = -1;
                            }
                            if (size3 < 0) {
                                ᵹˉᵞ.ᵸˑ(AbstractC1327.m4105("A required type converter (", c55632.m11198(), ") for ", c5563.m11198(), " is missing in the database configuration."));
                                return null;
                            }
                            abstractC5069.f18939.put(c55632, list.get(size3));
                        }
                    }
                    int size4 = list.size() - 1;
                    if (size4 >= 0) {
                        while (true) {
                            int i9 = size4 - 1;
                            if (!zArr2[size4]) {
                                C0190.m1434("Unexpected type converter ", list.get(size4), ". Annotate TypeConverter class with @ProvidedTypeConverter annotation or remove this converter from the builder.");
                                return null;
                            }
                            if (i9 < 0) {
                                break;
                            }
                            size4 = i9;
                        }
                    }
                    abstractC5069.f18942 = ᵳʿˉ.ᵥᵯˎ(interfaceC22622.mo1762(new C3050((InterfaceC3506) interfaceC22622.mo1764(ʾᵠᵦ.ᵾᵬ))));
                    AbstractC2687 abstractC2687 = (AbstractC2687) interfaceC22622.mo1764(ˉːᵡ.ᵿʗᵝʽ);
                    AbstractC1566 abstractC1566 = abstractC2687 instanceof AbstractC1566 ? (AbstractC1566) abstractC2687 : null;
                    if (abstractC1566 == null || (executorC0374 = abstractC1566.mo1229()) == null) {
                        executorC0374 = new ExecutorC0374(abstractC2687);
                    }
                    abstractC5069.f18943 = executorC0374;
                    return abstractC5069;
                }
                C5563 c55633 = (C5563) it2.next();
                int size5 = arrayList3.size() - 1;
                if (size5 >= 0) {
                    while (true) {
                        int i10 = size5 - 1;
                        if (c55633.m11197(arrayList3.get(size5))) {
                            zArr[size5] = true;
                            i4 = size5;
                            break;
                        }
                        if (i10 < 0) {
                            break;
                        }
                        size5 = i10;
                    }
                }
                if (i4 < 0) {
                    ᵹˉᵞ.ᵸˑ(AbstractC4486.m9550("A required auto migration spec (", c55633.m11198(), ") is missing in the database configuration."));
                    return null;
                }
                linkedHashMap.put(c55633, arrayList3.get(i4));
            }
        } catch (ClassNotFoundException e) {
            ᵨᴵᵺ.ᵪʩ(AbstractC1327.m4105("Cannot find implementation for ", cls.getCanonicalName(), ". ", strConcat, " does not exist. Is Room annotation processor correctly configured?"), e);
            return null;
        } catch (IllegalAccessException e2) {
            ᵨᴵᵺ.ᵪʩ(AbstractC4486.m9562("Cannot access the constructor ", cls.getCanonicalName()), e2);
            return null;
        } catch (InstantiationException e3) {
            ᵨᴵᵺ.ᵪʩ(AbstractC4486.m9562("Failed to create an instance of ", cls.getCanonicalName()), e3);
            return null;
        }
    }
}
