package sq;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import qq.b;
import qq.d;

/* loaded from: classes3.dex */
public class a {

    /* renamed from: a, reason: collision with root package name */
    public final boolean f35966a;

    /* renamed from: b, reason: collision with root package name */
    public final String[] f35967b;

    /* renamed from: c, reason: collision with root package name */
    public final boolean[] f35968c;

    /* renamed from: d, reason: collision with root package name */
    public final String f35969d;

    /* renamed from: sq.a$a, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    public static class C0846a {

        /* renamed from: a, reason: collision with root package name */
        Map f35970a = new HashMap();

        /* renamed from: b, reason: collision with root package name */
        Map f35971b = new HashMap();

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: sq.a$a$a, reason: collision with other inner class name */
        /* loaded from: classes3.dex */
        public class C0847a implements Comparable {

            /* renamed from: p, reason: collision with root package name */
            String f35972p;

            /* renamed from: q, reason: collision with root package name */
            boolean f35973q;

            /* renamed from: r, reason: collision with root package name */
            int f35974r;

            public C0847a(String str, boolean z10, int i10) {
                this.f35972p = str;
                this.f35973q = z10;
                this.f35974r = i10;
            }

            @Override // java.lang.Comparable
            /* renamed from: a, reason: merged with bridge method [inline-methods] */
            public int compareTo(C0847a c0847a) {
                int i10 = this.f35974r;
                int i11 = c0847a.f35974r;
                if (i10 < i11) {
                    return -1;
                }
                if (i10 > i11) {
                    return 1;
                }
                throw new IllegalArgumentException(String.format("Columns '%s' and '%s' cannot have the same composite index order %d", this.f35972p, c0847a.f35972p, Integer.valueOf(this.f35974r)));
            }

            public boolean equals(Object obj) {
                if (this == obj) {
                    return true;
                }
                if (obj == null || getClass() != obj.getClass()) {
                    return false;
                }
                C0847a c0847a = (C0847a) obj;
                String str = this.f35972p;
                if (str == null) {
                    if (c0847a.f35972p != null) {
                        return false;
                    }
                } else if (!str.equals(c0847a.f35972p)) {
                    return false;
                }
                return true;
            }

            public int hashCode() {
                String str = this.f35972p;
                return 31 + (str == null ? 0 : str.hashCode());
            }
        }

        private void a(String str, Map map, boolean z10, int i10, String str2) {
            Set set = (Set) map.get(str2);
            if (set == null) {
                set = new HashSet();
                map.put(str2, set);
            }
            if (!set.add(new C0847a(str, z10, i10))) {
                throw new IllegalArgumentException(String.format("Column '%s' has two indexes with the same name %s", str, str2));
            }
        }

        private void b(String str, Map map, b[] bVarArr) {
            for (b bVar : bVarArr) {
                a(str, map, bVar.ascending(), bVar.order(), bVar.indexName());
            }
        }

        public void c(String str, String str2, d dVar) {
            boolean z10;
            boolean z11 = true;
            if (dVar.indexNames().length != 0) {
                b(str2, this.f35970a, dVar.indexNames());
                z10 = true;
            } else {
                z10 = false;
            }
            if (dVar.uniqueNames().length != 0) {
                b(str2, this.f35971b, dVar.uniqueNames());
            } else {
                z11 = z10;
            }
            if (z11) {
                return;
            }
            a(str2, dVar.unique() ? this.f35971b : this.f35970a, true, 0, String.format("%s_%s", str, str2));
        }

        public void d(String str, boolean z10, List list, Set set) {
            ArrayList arrayList = new ArrayList(set);
            Collections.sort(arrayList);
            int size = arrayList.size();
            String[] strArr = new String[size];
            boolean[] zArr = new boolean[size];
            for (int i10 = 0; i10 < size; i10++) {
                C0847a c0847a = (C0847a) arrayList.get(i10);
                strArr[i10] = c0847a.f35972p;
                zArr[i10] = c0847a.f35973q;
            }
            list.add(new a(z10, strArr, zArr, str));
        }

        public List e() {
            ArrayList arrayList = new ArrayList();
            HashSet hashSet = new HashSet();
            for (Map.Entry entry : this.f35970a.entrySet()) {
                String str = (String) entry.getKey();
                hashSet.add(str);
                d(str, false, arrayList, (Set) entry.getValue());
            }
            for (Map.Entry entry2 : this.f35971b.entrySet()) {
                String str2 = (String) entry2.getKey();
                if (!hashSet.add(str2)) {
                    throw new IllegalArgumentException(String.format("There are both unique and non-unique indexes with the same name : %s", str2));
                }
                d(str2, true, arrayList, (Set) entry2.getValue());
            }
            return arrayList;
        }

        public Map f() {
            HashMap hashMap = new HashMap();
            for (a aVar : e()) {
                hashMap.put(aVar.f35969d, aVar);
            }
            return hashMap;
        }
    }

    public a(boolean z10, String[] strArr, boolean[] zArr, String str) {
        this.f35966a = z10;
        this.f35967b = strArr;
        this.f35968c = zArr;
        this.f35969d = str;
    }

    public String a(String str) {
        return b(str, true);
    }

    public String b(String str, boolean z10) {
        StringBuilder sb2 = new StringBuilder("create ");
        if (this.f35966a) {
            sb2.append("unique ");
        }
        sb2.append("index ");
        if (z10) {
            sb2.append("if not exists ");
        }
        sb2.append("_cb");
        sb2.append(this.f35969d);
        sb2.append(" on %s (");
        int length = this.f35967b.length;
        sb2.append('\'');
        sb2.append(this.f35967b[0]);
        sb2.append("' ");
        sb2.append(this.f35968c[0] ? "ASC" : "DESC");
        for (int i10 = 1; i10 < length; i10++) {
            sb2.append(", '");
            sb2.append(this.f35967b[i10]);
            sb2.append("' ");
            sb2.append(this.f35968c[i10] ? "ASC" : "DESC");
        }
        sb2.append(')');
        return String.format(sb2.toString(), str, Boolean.valueOf(z10));
    }
}
