package bo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import qn.j;
import sm.y0;

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

    /* renamed from: c, reason: collision with root package name */
    private static final C0184a f7045c = new C0184a(null);

    /* renamed from: d, reason: collision with root package name */
    private static final Map f7046d;

    /* renamed from: a, reason: collision with root package name */
    private final x f7047a;

    /* renamed from: b, reason: collision with root package name */
    private final ConcurrentHashMap f7048b;

    /* renamed from: bo.a$a, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    private static final class C0184a {
        private C0184a() {
        }

        public /* synthetic */ C0184a(kotlin.jvm.internal.k kVar) {
            this();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public static final class b extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final b f7049p = new b();

        b() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean invoke(Object extractNullability) {
            kotlin.jvm.internal.t.g(extractNullability, "$this$extractNullability");
            return Boolean.FALSE;
        }
    }

    static {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        for (bo.b bVar : bo.b.values()) {
            String javaTarget = bVar.getJavaTarget();
            if (linkedHashMap.get(javaTarget) == null) {
                linkedHashMap.put(javaTarget, bVar);
            }
        }
        f7046d = linkedHashMap;
    }

    public a(x javaTypeEnhancementState) {
        kotlin.jvm.internal.t.g(javaTypeEnhancementState, "javaTypeEnhancementState");
        this.f7047a = javaTypeEnhancementState;
        this.f7048b = new ConcurrentHashMap();
    }

    private final Set a(Set set) {
        Set V0;
        Set j10;
        Set k10;
        if (!set.contains(bo.b.TYPE_USE)) {
            return set;
        }
        V0 = sm.p.V0(bo.b.values());
        j10 = y0.j(V0, bo.b.TYPE_PARAMETER_BOUNDS);
        k10 = y0.k(j10, set);
        return k10;
    }

    private final r d(Object obj) {
        jo.i g10;
        r r10 = r(obj);
        if (r10 != null) {
            return r10;
        }
        rm.v t10 = t(obj);
        if (t10 == null) {
            return null;
        }
        Object a10 = t10.a();
        Set set = (Set) t10.b();
        g0 q10 = q(obj);
        if (q10 == null) {
            q10 = p(a10);
        }
        if (q10.isIgnore() || (g10 = g(a10, b.f7049p)) == null) {
            return null;
        }
        return new r(jo.i.b(g10, null, q10.isWarning(), 1, null), set, false, 4, null);
    }

    private final jo.i g(Object obj, dn.l lVar) {
        jo.i n10;
        jo.i n11 = n(obj, ((Boolean) lVar.invoke(obj)).booleanValue());
        if (n11 != null) {
            return n11;
        }
        Object s10 = s(obj);
        if (s10 == null) {
            return null;
        }
        g0 p10 = p(obj);
        if (p10.isIgnore() || (n10 = n(s10, ((Boolean) lVar.invoke(s10)).booleanValue())) == null) {
            return null;
        }
        return jo.i.b(n10, null, p10.isWarning(), 1, null);
    }

    private final Object h(Object obj, ro.c cVar) {
        for (Object obj2 : k(obj)) {
            if (kotlin.jvm.internal.t.b(i(obj2), cVar)) {
                return obj2;
            }
        }
        return null;
    }

    private final boolean l(Object obj, ro.c cVar) {
        Iterable k10 = k(obj);
        if ((k10 instanceof Collection) && ((Collection) k10).isEmpty()) {
            return false;
        }
        Iterator it = k10.iterator();
        while (it.hasNext()) {
            if (kotlin.jvm.internal.t.b(i(it.next()), cVar)) {
                return true;
            }
        }
        return false;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x0091, code lost:
    
        if (r6.equals("ALWAYS") != false) goto L48;
     */
    /* JADX WARN: Code restructure failed: missing block: B:42:0x00a6, code lost:
    
        if (r6.equals("NEVER") == false) goto L47;
     */
    /* JADX WARN: Code restructure failed: missing block: B:43:0x00b2, code lost:
    
        r6 = jo.h.NULLABLE;
     */
    /* JADX WARN: Code restructure failed: missing block: B:45:0x00af, code lost:
    
        if (r6.equals("MAYBE") == false) goto L47;
     */
    /* JADX WARN: Failed to find 'out' block for switch in B:35:0x0087. Please report as an issue. */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final jo.i n(Object obj, boolean z10) {
        jo.h hVar;
        Object d02;
        ro.c i10 = i(obj);
        if (i10 == null) {
            return null;
        }
        g0 g0Var = (g0) this.f7047a.c().invoke(i10);
        if (g0Var.isIgnore()) {
            return null;
        }
        if (c0.o().contains(i10)) {
            hVar = jo.h.NULLABLE;
        } else if (c0.n().contains(i10)) {
            hVar = jo.h.NOT_NULL;
        } else {
            if (kotlin.jvm.internal.t.b(i10, c0.j()) ? true : kotlin.jvm.internal.t.b(i10, c0.g())) {
                hVar = jo.h.NULLABLE;
            } else {
                if (kotlin.jvm.internal.t.b(i10, c0.k()) ? true : kotlin.jvm.internal.t.b(i10, c0.h())) {
                    hVar = jo.h.FORCE_FLEXIBILITY;
                } else if (kotlin.jvm.internal.t.b(i10, c0.f())) {
                    d02 = sm.c0.d0(b(obj, false));
                    String str = (String) d02;
                    if (str != null) {
                        switch (str.hashCode()) {
                            case 73135176:
                                break;
                            case 74175084:
                                break;
                            case 433141802:
                                if (str.equals("UNKNOWN")) {
                                    hVar = jo.h.FORCE_FLEXIBILITY;
                                    break;
                                }
                                return null;
                            case 1933739535:
                                break;
                            default:
                                return null;
                        }
                    }
                    hVar = jo.h.NOT_NULL;
                } else if (kotlin.jvm.internal.t.b(i10, c0.d())) {
                    hVar = jo.h.NULLABLE;
                } else if (kotlin.jvm.internal.t.b(i10, c0.c())) {
                    hVar = jo.h.NOT_NULL;
                } else if (kotlin.jvm.internal.t.b(i10, c0.a())) {
                    hVar = jo.h.NOT_NULL;
                } else {
                    if (!kotlin.jvm.internal.t.b(i10, c0.b())) {
                        return null;
                    }
                    hVar = jo.h.NULLABLE;
                }
            }
        }
        return new jo.i(hVar, g0Var.isWarning() || z10);
    }

    private final g0 o(Object obj) {
        ro.c i10 = i(obj);
        return (i10 == null || !c.c().containsKey(i10)) ? p(obj) : (g0) this.f7047a.c().invoke(i10);
    }

    private final g0 p(Object obj) {
        g0 q10 = q(obj);
        return q10 != null ? q10 : this.f7047a.d().a();
    }

    private final g0 q(Object obj) {
        Iterable b10;
        Object d02;
        g0 g0Var = (g0) this.f7047a.d().c().get(i(obj));
        if (g0Var != null) {
            return g0Var;
        }
        Object h10 = h(obj, c.d());
        if (h10 == null || (b10 = b(h10, false)) == null) {
            return null;
        }
        d02 = sm.c0.d0(b10);
        String str = (String) d02;
        if (str == null) {
            return null;
        }
        g0 b11 = this.f7047a.d().b();
        if (b11 != null) {
            return b11;
        }
        int hashCode = str.hashCode();
        if (hashCode == -2137067054) {
            if (str.equals("IGNORE")) {
                return g0.IGNORE;
            }
            return null;
        }
        if (hashCode == -1838656823) {
            if (str.equals("STRICT")) {
                return g0.STRICT;
            }
            return null;
        }
        if (hashCode == 2656902 && str.equals("WARN")) {
            return g0.WARN;
        }
        return null;
    }

    private final r r(Object obj) {
        r rVar;
        if (this.f7047a.b() || (rVar = (r) c.a().get(i(obj))) == null) {
            return null;
        }
        g0 o10 = o(obj);
        if (!(o10 != g0.IGNORE)) {
            o10 = null;
        }
        if (o10 == null) {
            return null;
        }
        return r.b(rVar, jo.i.b(rVar.d(), null, o10.isWarning(), 1, null), null, false, 6, null);
    }

    private final rm.v t(Object obj) {
        Object h10;
        Object obj2;
        if (this.f7047a.d().d() || (h10 = h(obj, c.e())) == null) {
            return null;
        }
        Iterator it = k(obj).iterator();
        while (true) {
            if (!it.hasNext()) {
                obj2 = null;
                break;
            }
            obj2 = it.next();
            if (s(obj2) != null) {
                break;
            }
        }
        if (obj2 == null) {
            return null;
        }
        Iterable b10 = b(h10, true);
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        Iterator it2 = b10.iterator();
        while (it2.hasNext()) {
            bo.b bVar = (bo.b) f7046d.get((String) it2.next());
            if (bVar != null) {
                linkedHashSet.add(bVar);
            }
        }
        return new rm.v(obj2, a(linkedHashSet));
    }

    protected abstract Iterable b(Object obj, boolean z10);

    public final y c(y yVar, Iterable annotations) {
        EnumMap b10;
        kotlin.jvm.internal.t.g(annotations, "annotations");
        if (this.f7047a.b()) {
            return yVar;
        }
        ArrayList<r> arrayList = new ArrayList();
        Iterator it = annotations.iterator();
        while (it.hasNext()) {
            r d10 = d(it.next());
            if (d10 != null) {
                arrayList.add(d10);
            }
        }
        if (arrayList.isEmpty()) {
            return yVar;
        }
        EnumMap enumMap = (yVar == null || (b10 = yVar.b()) == null) ? new EnumMap(bo.b.class) : new EnumMap(b10);
        boolean z10 = false;
        for (r rVar : arrayList) {
            Iterator it2 = rVar.e().iterator();
            while (it2.hasNext()) {
                enumMap.put((EnumMap) it2.next(), (bo.b) rVar);
                z10 = true;
            }
        }
        return !z10 ? yVar : new y(enumMap);
    }

    public final jo.f e(Iterable annotations) {
        jo.f fVar;
        kotlin.jvm.internal.t.g(annotations, "annotations");
        Iterator it = annotations.iterator();
        jo.f fVar2 = null;
        while (it.hasNext()) {
            ro.c i10 = i(it.next());
            if (c0.p().contains(i10)) {
                fVar = jo.f.READ_ONLY;
            } else if (c0.m().contains(i10)) {
                fVar = jo.f.MUTABLE;
            } else {
                continue;
            }
            if (fVar2 != null && fVar2 != fVar) {
                return null;
            }
            fVar2 = fVar;
        }
        return fVar2;
    }

    public final jo.i f(Iterable annotations, dn.l forceWarning) {
        kotlin.jvm.internal.t.g(annotations, "annotations");
        kotlin.jvm.internal.t.g(forceWarning, "forceWarning");
        Iterator it = annotations.iterator();
        jo.i iVar = null;
        while (it.hasNext()) {
            jo.i g10 = g(it.next(), forceWarning);
            if (iVar != null) {
                if (g10 != null && !kotlin.jvm.internal.t.b(g10, iVar) && (!g10.d() || iVar.d())) {
                    if (g10.d() || !iVar.d()) {
                        return null;
                    }
                }
            }
            iVar = g10;
        }
        return iVar;
    }

    protected abstract ro.c i(Object obj);

    protected abstract Object j(Object obj);

    protected abstract Iterable k(Object obj);

    public final boolean m(Object annotation) {
        kotlin.jvm.internal.t.g(annotation, "annotation");
        Object h10 = h(annotation, j.a.H);
        if (h10 == null) {
            return false;
        }
        Iterable b10 = b(h10, false);
        if ((b10 instanceof Collection) && ((Collection) b10).isEmpty()) {
            return false;
        }
        Iterator it = b10.iterator();
        while (it.hasNext()) {
            if (kotlin.jvm.internal.t.b((String) it.next(), "TYPE")) {
                return true;
            }
        }
        return false;
    }

    public final Object s(Object annotation) {
        boolean U;
        Object obj;
        kotlin.jvm.internal.t.g(annotation, "annotation");
        if (this.f7047a.d().d()) {
            return null;
        }
        U = sm.c0.U(c.b(), i(annotation));
        if (U || l(annotation, c.f())) {
            return annotation;
        }
        if (!l(annotation, c.g())) {
            return null;
        }
        ConcurrentHashMap concurrentHashMap = this.f7048b;
        Object j10 = j(annotation);
        Object obj2 = concurrentHashMap.get(j10);
        if (obj2 != null) {
            return obj2;
        }
        Iterator it = k(annotation).iterator();
        while (true) {
            if (!it.hasNext()) {
                obj = null;
                break;
            }
            obj = s(it.next());
            if (obj != null) {
                break;
            }
        }
        if (obj == null) {
            return null;
        }
        Object putIfAbsent = concurrentHashMap.putIfAbsent(j10, obj);
        return putIfAbsent == null ? obj : putIfAbsent;
    }
}
