package h.b.p.a0;

import h.b.p.a0.h;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/* JADX INFO: compiled from: JsonNamesMap.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class n {
    public static final h.a<Map<String, Integer>> a = new h.a<>();

    /* JADX INFO: compiled from: JsonNamesMap.kt */
    @g.i
    public /* synthetic */ class a extends g.h0.c.j implements g.h0.b.a<Map<String, ? extends Integer>> {
        public a(Object obj) {
            super(0, obj, n.class, "buildAlternativeNamesMap", "buildAlternativeNamesMap(Lkotlinx/serialization/descriptors/SerialDescriptor;)Ljava/util/Map;", 1);
        }

        @Override // g.h0.b.a
        public Map<String, ? extends Integer> invoke() {
            return n.a((h.b.m.e) this.receiver);
        }
    }

    public static final Map<String, Integer> a(h.b.m.e eVar) {
        String[] strArrNames;
        g.h0.c.l.f(eVar, "<this>");
        int iF = eVar.f();
        ConcurrentHashMap concurrentHashMap = null;
        for (int i2 = 0; i2 < iF; i2++) {
            List<Annotation> listH = eVar.h(i2);
            ArrayList arrayList = new ArrayList();
            for (Object obj : listH) {
                if (obj instanceof h.b.p.t) {
                    arrayList.add(obj);
                }
            }
            g.h0.c.l.f(arrayList, "<this>");
            h.b.p.t tVar = (h.b.p.t) (arrayList.size() == 1 ? arrayList.get(0) : null);
            if (tVar != null && (strArrNames = tVar.names()) != null) {
                for (String str : strArrNames) {
                    if (concurrentHashMap == null) {
                        concurrentHashMap = new ConcurrentHashMap(eVar.f());
                    }
                    g.h0.c.l.c(concurrentHashMap);
                    if (concurrentHashMap.containsKey(str)) {
                        StringBuilder sbE = d.b.a.a.a.E("The suggested name '", str, "' for property ");
                        sbE.append(eVar.g(i2));
                        sbE.append(" is already one of the names for property ");
                        sbE.append(eVar.g(((Number) g.c0.g.o(concurrentHashMap, str)).intValue()));
                        sbE.append(" in ");
                        sbE.append(eVar);
                        throw new m(sbE.toString());
                    }
                    concurrentHashMap.put(str, Integer.valueOf(i2));
                }
            }
        }
        if (concurrentHashMap != null) {
            return concurrentHashMap;
        }
        g.c0.g.i();
        return g.c0.m.f4068b;
    }

    public static final int b(h.b.m.e eVar, h.b.p.a aVar, String str) {
        g.h0.c.l.f(eVar, "<this>");
        g.h0.c.l.f(aVar, "json");
        g.h0.c.l.f(str, "name");
        int iD = eVar.d(str);
        if (iD != -3 || !aVar.f4485b.f4572l) {
            return iD;
        }
        Integer num = (Integer) ((Map) f.a.y.a.i0(aVar).b(eVar, a, new a(eVar))).get(str);
        if (num != null) {
            return num.intValue();
        }
        return -3;
    }

    public static final int c(h.b.m.e eVar, h.b.p.a aVar, String str, String str2) {
        g.h0.c.l.f(eVar, "<this>");
        g.h0.c.l.f(aVar, "json");
        g.h0.c.l.f(str, "name");
        g.h0.c.l.f(str2, "suffix");
        int iB = b(eVar, aVar, str);
        if (iB != -3) {
            return iB;
        }
        throw new h.b.i(eVar.a() + " does not contain element with name '" + str + '\'' + str2);
    }
}
