package p138.p176.p291.p295;

import com.google.firebase.components.DependencyCycleException;
import com.google.firebase.components.MissingDependencyException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p176.p291.p318.InterfaceC5898;
import p138.p176.p291.p318.InterfaceC5899;
import p138.p176.p291.p322.InterfaceC5963;

/* JADX INFO: renamed from: ދ.ހ.ށ.ރ.ފ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C5594 extends AbstractC5580 {

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public static final InterfaceC5963<Set<Object>> f16033 = new InterfaceC5963() { // from class: ދ.ހ.ށ.ރ.މ
        @Override // p138.p176.p291.p322.InterfaceC5963
        public Object get() {
            return Collections.emptySet();
        }
    };

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Map<C5583<?>, C5601<?>> f16034 = new HashMap();

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Map<Class<?>, C5601<?>> f16035 = new HashMap();

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final Map<Class<?>, C5601<Set<?>>> f16036 = new HashMap();

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C5600 f16037;

    public C5594(Executor executor, Iterable<InterfaceC5590> iterable, C5583<?>... c5583Arr) {
        Set<C5596> set;
        this.f16037 = new C5600(executor);
        ArrayList<C5583> arrayList = new ArrayList();
        arrayList.add(C5583.m8946(this.f16037, C5600.class, InterfaceC5899.class, InterfaceC5898.class));
        Iterator<InterfaceC5590> it = iterable.iterator();
        while (it.hasNext()) {
            arrayList.addAll(it.next().getComponents());
        }
        for (C5583<?> c5583 : c5583Arr) {
            if (c5583 != null) {
                arrayList.add(c5583);
            }
        }
        HashMap map = new HashMap(arrayList.size());
        for (C5583 c55832 : arrayList) {
            C5596 c5596 = new C5596(c55832);
            Iterator it2 = c55832.f16016.iterator();
            while (it2.hasNext()) {
                Class cls = (Class) it2.next();
                C5597 c5597 = new C5597(cls, !c55832.m8947(), null);
                if (!map.containsKey(c5597)) {
                    map.put(c5597, new HashSet());
                }
                Set set2 = (Set) map.get(c5597);
                if (!set2.isEmpty() && !c5597.f16042) {
                    throw new IllegalArgumentException(String.format("Multiple components provide %s.", cls));
                }
                set2.add(c5596);
            }
        }
        Iterator it3 = map.values().iterator();
        while (it3.hasNext()) {
            for (C5596 c55962 : (Set) it3.next()) {
                for (C5598 c5598 : c55962.f16038.f16017) {
                    if ((c5598.f16045 == 0) && (set = (Set) map.get(new C5597(c5598.f16043, c5598.m8958(), null))) != null) {
                        for (C5596 c55963 : set) {
                            c55962.f16039.add(c55963);
                            c55963.f16040.add(c55962);
                        }
                    }
                }
            }
        }
        HashSet<C5596> hashSet = new HashSet();
        Iterator it4 = map.values().iterator();
        while (it4.hasNext()) {
            hashSet.addAll((Set) it4.next());
        }
        HashSet hashSet2 = new HashSet();
        for (C5596 c55964 : hashSet) {
            if (c55964.m8956()) {
                hashSet2.add(c55964);
            }
        }
        int i = 0;
        while (!hashSet2.isEmpty()) {
            C5596 c55965 = (C5596) hashSet2.iterator().next();
            hashSet2.remove(c55965);
            i++;
            for (C5596 c55966 : c55965.f16039) {
                c55966.f16040.remove(c55965);
                if (c55966.m8956()) {
                    hashSet2.add(c55966);
                }
            }
        }
        if (i != arrayList.size()) {
            ArrayList arrayList2 = new ArrayList();
            for (C5596 c55967 : hashSet) {
                if (!c55967.m8956() && !c55967.f16039.isEmpty()) {
                    arrayList2.add(c55967.f16038);
                }
            }
            throw new DependencyCycleException(arrayList2);
        }
        Iterator it5 = arrayList.iterator();
        while (it5.hasNext()) {
            final C5583<?> c55833 = (C5583) it5.next();
            this.f16034.put(c55833, new C5601<>(new InterfaceC5963(this, c55833) { // from class: ދ.ހ.ށ.ރ.އ

                /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
                public final C5594 f16029;

                /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
                public final C5583 f16030;

                {
                    this.f16029 = this;
                    this.f16030 = c55833;
                }

                @Override // p138.p176.p291.p322.InterfaceC5963
                public Object get() {
                    C5594 c5594 = this.f16029;
                    C5583 c55834 = this.f16030;
                    return c55834.f16020.mo8939(new C5602(c55834, c5594));
                }
            }));
        }
        for (Map.Entry<C5583<?>, C5601<?>> entry : this.f16034.entrySet()) {
            C5583<?> key = entry.getKey();
            if (key.m8947()) {
                C5601<?> value = entry.getValue();
                Iterator<Class<? super Object>> it6 = key.f16016.iterator();
                while (it6.hasNext()) {
                    this.f16035.put(it6.next(), value);
                }
            }
        }
        for (C5583<?> c55834 : this.f16034.keySet()) {
            for (C5598 c55982 : c55834.f16017) {
                if ((c55982.f16044 == 1) && !this.f16035.containsKey(c55982.f16043)) {
                    throw new MissingDependencyException(String.format("Unsatisfied dependency for component %s: %s", c55834, c55982.f16043));
                }
            }
        }
        HashMap map2 = new HashMap();
        for (Map.Entry<C5583<?>, C5601<?>> entry2 : this.f16034.entrySet()) {
            C5583<?> key2 = entry2.getKey();
            if (!key2.m8947()) {
                C5601<?> value2 = entry2.getValue();
                for (Class<? super Object> cls2 : key2.f16016) {
                    if (!map2.containsKey(cls2)) {
                        map2.put(cls2, new HashSet());
                    }
                    ((Set) map2.get(cls2)).add(value2);
                }
            }
        }
        for (Map.Entry entry3 : map2.entrySet()) {
            final Set set3 = (Set) entry3.getValue();
            this.f16036.put((Class) entry3.getKey(), new C5601<>(new InterfaceC5963(set3) { // from class: ދ.ހ.ށ.ރ.ވ

                /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
                public final Set f16031;

                {
                    this.f16031 = set3;
                }

                @Override // p138.p176.p291.p322.InterfaceC5963
                public Object get() {
                    return C5594.m8955(this.f16031);
                }
            }));
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static /* synthetic */ Set m8955(Set set) {
        HashSet hashSet = new HashSet();
        Iterator it = set.iterator();
        while (it.hasNext()) {
            hashSet.add(((C5601) it.next()).get());
        }
        return Collections.unmodifiableSet(hashSet);
    }

    @Override // p138.p176.p291.p295.InterfaceC5586
    /* JADX INFO: renamed from: ހ */
    public <T> InterfaceC5963<T> mo8952(Class<T> cls) {
        C4303.m7008(cls, "Null interface requested.");
        return this.f16035.get(cls);
    }

    @Override // p138.p176.p291.p295.InterfaceC5586
    /* JADX INFO: renamed from: ށ */
    public <T> InterfaceC5963<Set<T>> mo8953(Class<T> cls) {
        C5601<Set<?>> c5601 = this.f16036.get(cls);
        return c5601 != null ? c5601 : (InterfaceC5963<Set<T>>) f16033;
    }
}
