package e.a.r.y;

import e.a.r.y.s;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/* JADX INFO: compiled from: JsonNamesMap.kt */
/* JADX INFO: loaded from: classes.dex */
@d.n
public final class z {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final s.a<Map<String, Integer>> f3058a = new s.a<>();

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

        @Override // d.n0.b.a
        /* JADX INFO: renamed from: l, reason: merged with bridge method [inline-methods] */
        public final Map<String, Integer> a() {
            return z.a((e.a.o.f) this.f2630e);
        }
    }

    public static final Map<String, Integer> a(e.a.o.f fVar) {
        String[] strArrNames;
        d.n0.c.s.e(fVar, "<this>");
        int iG = fVar.g();
        Map<String, Integer> mapA = null;
        for (int i = 0; i < iG; i++) {
            List<Annotation> listJ = fVar.j(i);
            ArrayList arrayList = new ArrayList();
            for (Object obj : listJ) {
                if (obj instanceof e.a.r.q) {
                    arrayList.add(obj);
                }
            }
            e.a.r.q qVar = (e.a.r.q) d.j0.n.y(arrayList);
            if (qVar != null && (strArrNames = qVar.names()) != null) {
                for (String str : strArrNames) {
                    if (mapA == null) {
                        mapA = r.a(fVar.g());
                    }
                    d.n0.c.s.b(mapA);
                    b(mapA, fVar, str, i);
                }
            }
        }
        return mapA == null ? d.j0.l0.e() : mapA;
    }

    private static final void b(Map<String, Integer> map, e.a.o.f fVar, String str, int i) {
        if (!map.containsKey(str)) {
            map.put(str, Integer.valueOf(i));
            return;
        }
        throw new x("The suggested name '" + str + "' for property " + fVar.h(i) + " is already one of the names for property " + fVar.h(((Number) d.j0.i0.f(map, str)).intValue()) + " in " + fVar);
    }

    public static final s.a<Map<String, Integer>> c() {
        return f3058a;
    }

    public static final int d(e.a.o.f fVar, e.a.r.a aVar, String str) {
        d.n0.c.s.e(fVar, "<this>");
        d.n0.c.s.e(aVar, "json");
        d.n0.c.s.e(str, "name");
        int iD = fVar.d(str);
        if (iD != -3 || !aVar.d().j()) {
            return iD;
        }
        Integer num = (Integer) ((Map) e.a.r.x.a(aVar).b(fVar, f3058a, new a(fVar))).get(str);
        if (num != null) {
            return num.intValue();
        }
        return -3;
    }

    public static final int e(e.a.o.f fVar, e.a.r.a aVar, String str, String str2) {
        d.n0.c.s.e(fVar, "<this>");
        d.n0.c.s.e(aVar, "json");
        d.n0.c.s.e(str, "name");
        d.n0.c.s.e(str2, "suffix");
        int iD = d(fVar, aVar, str);
        if (iD != -3) {
            return iD;
        }
        throw new e.a.i(fVar.a() + " does not contain element with name '" + str + '\'' + str2);
    }

    public static /* synthetic */ int f(e.a.o.f fVar, e.a.r.a aVar, String str, String str2, int i, Object obj) {
        if ((i & 4) != 0) {
            str2 = "";
        }
        return e(fVar, aVar, str, str2);
    }
}
