package h.b.p.a0;

import h.b.m.j;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/* JADX INFO: compiled from: TreeJsonDecoder.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public class r extends b {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final h.b.p.w f4525f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final String f4526g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final h.b.m.e f4527h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f4528i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f4529j;

    /* JADX INFO: compiled from: TreeJsonDecoder.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);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public r(h.b.p.a aVar, h.b.p.w wVar, String str, h.b.m.e eVar, int i2) {
        super(aVar, wVar, null);
        int i3 = i2 & 4;
        int i4 = i2 & 8;
        g.h0.c.l.f(aVar, "json");
        g.h0.c.l.f(wVar, "value");
        this.f4525f = wVar;
        this.f4526g = null;
        this.f4527h = null;
    }

    @Override // h.b.o.s0
    public String W(h.b.m.e eVar, int i2) {
        Object next;
        g.h0.c.l.f(eVar, "desc");
        String strG = eVar.g(i2);
        if (!this.f4500e.f4572l || c0().keySet().contains(strG)) {
            return strG;
        }
        Map map = (Map) f.a.y.a.i0(this.f4498c).b(eVar, n.a, new a(eVar));
        Iterator<T> it = c0().keySet().iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            }
            next = it.next();
            Integer num = (Integer) map.get((String) next);
            if (num != null && num.intValue() == i2) {
                break;
            }
        }
        String str = (String) next;
        return str == null ? strG : str;
    }

    @Override // h.b.p.a0.b
    public h.b.p.h Z(String str) {
        g.h0.c.l.f(str, "tag");
        return (h.b.p.h) g.c0.g.o(c0(), str);
    }

    @Override // h.b.p.a0.b, h.b.n.c
    public void a(h.b.m.e eVar) {
        Set<String> setT0;
        g.h0.c.l.f(eVar, "descriptor");
        if (this.f4500e.f4562b || (eVar.e() instanceof h.b.m.c)) {
            return;
        }
        if (this.f4500e.f4572l) {
            Set<String> setT02 = f.a.y.a.t0(eVar);
            Map map = (Map) f.a.y.a.i0(this.f4498c).a(eVar, n.a);
            Set setKeySet = map != null ? map.keySet() : null;
            if (setKeySet == null) {
                setKeySet = g.c0.n.f4069b;
            }
            g.h0.c.l.f(setT02, "<this>");
            g.h0.c.l.f(setKeySet, "elements");
            g.h0.c.l.f(setKeySet, "<this>");
            Integer numValueOf = Integer.valueOf(setKeySet.size());
            LinkedHashSet linkedHashSet = new LinkedHashSet(f.a.y.a.x0(numValueOf != null ? setT02.size() + numValueOf.intValue() : setT02.size() * 2));
            linkedHashSet.addAll(setT02);
            g.c0.g.a(linkedHashSet, setKeySet);
            setT0 = linkedHashSet;
        } else {
            setT0 = f.a.y.a.t0(eVar);
        }
        for (String str : c0().keySet()) {
            if (!setT0.contains(str) && !g.h0.c.l.a(str, this.f4526g)) {
                String string = c0().toString();
                g.h0.c.l.f(str, "key");
                g.h0.c.l.f(string, "input");
                throw f.a.y.a.e(-1, "Encountered unknown key '" + str + "'.\nUse 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.\nCurrent input: " + ((Object) f.a.y.a.z0(string, -1)));
            }
        }
    }

    @Override // h.b.p.a0.b, h.b.n.e
    public h.b.n.c c(h.b.m.e eVar) {
        g.h0.c.l.f(eVar, "descriptor");
        return eVar == this.f4527h ? this : super.c(eVar);
    }

    @Override // h.b.p.a0.b
    /* JADX INFO: renamed from: e0, reason: merged with bridge method [inline-methods] */
    public h.b.p.w c0() {
        return this.f4525f;
    }

    @Override // h.b.p.a0.b, h.b.o.n1, h.b.n.e
    public boolean u() {
        return !this.f4529j && super.u();
    }

    @Override // h.b.n.c
    public int x(h.b.m.e eVar) {
        g.h0.c.l.f(eVar, "descriptor");
        while (this.f4528i < eVar.f()) {
            int i2 = this.f4528i;
            this.f4528i = i2 + 1;
            String strU = U(eVar, i2);
            boolean z = true;
            int i3 = this.f4528i - 1;
            this.f4529j = false;
            if (!c0().containsKey(strU)) {
                boolean z2 = (this.f4498c.f4485b.f4566f || eVar.j(i3) || !eVar.i(i3).c()) ? false : true;
                this.f4529j = z2;
                if (!z2) {
                    continue;
                }
            }
            if (this.f4500e.f4568h) {
                h.b.p.a aVar = this.f4498c;
                h.b.m.e eVarI = eVar.i(i3);
                if (eVarI.c() || !(Z(strU) instanceof h.b.p.u)) {
                    if (g.h0.c.l.a(eVarI.e(), j.b.a)) {
                        h.b.p.h hVarZ = Z(strU);
                        String strB = null;
                        h.b.p.y yVar = hVarZ instanceof h.b.p.y ? (h.b.p.y) hVarZ : null;
                        if (yVar != null) {
                            g.h0.c.l.f(yVar, "<this>");
                            if (!(yVar instanceof h.b.p.u)) {
                                strB = yVar.b();
                            }
                        }
                        if (strB == null || n.b(eVarI, aVar, strB) != -3) {
                        }
                    }
                    z = false;
                }
                if (!z) {
                }
            }
            return i3;
        }
        return -1;
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public r(h.b.p.a aVar, h.b.p.w wVar, String str, h.b.m.e eVar) {
        super(aVar, wVar, null);
        g.h0.c.l.f(aVar, "json");
        g.h0.c.l.f(wVar, "value");
        this.f4525f = wVar;
        this.f4526g = str;
        this.f4527h = eVar;
    }
}
