package lq;

import hq.i;
import kotlin.text.z;

/* loaded from: classes3.dex */
public class p extends iq.a implements kq.f {

    /* renamed from: a, reason: collision with root package name */
    private final kq.a f28533a;

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

    /* renamed from: c, reason: collision with root package name */
    public final lq.a f28535c;

    /* renamed from: d, reason: collision with root package name */
    private final mq.b f28536d;

    /* renamed from: e, reason: collision with root package name */
    private int f28537e;

    /* renamed from: f, reason: collision with root package name */
    private a f28538f;

    /* renamed from: g, reason: collision with root package name */
    private final kq.e f28539g;

    /* renamed from: h, reason: collision with root package name */
    private final h f28540h;

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

        /* renamed from: a, reason: collision with root package name */
        public String f28541a;
    }

    /* loaded from: classes3.dex */
    public /* synthetic */ class b {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f28542a;

        static {
            int[] iArr = new int[t.values().length];
            try {
                iArr[t.LIST.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[t.MAP.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[t.POLY_OBJ.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[t.OBJ.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            f28542a = iArr;
        }
    }

    public p(kq.a json, t mode, lq.a lexer, hq.e descriptor, a aVar) {
        kotlin.jvm.internal.t.g(json, "json");
        kotlin.jvm.internal.t.g(mode, "mode");
        kotlin.jvm.internal.t.g(lexer, "lexer");
        kotlin.jvm.internal.t.g(descriptor, "descriptor");
        this.f28533a = json;
        this.f28534b = mode;
        this.f28535c = lexer;
        this.f28536d = json.c();
        this.f28537e = -1;
        this.f28538f = aVar;
        kq.e b10 = json.b();
        this.f28539g = b10;
        this.f28540h = b10.g() ? null : new h(descriptor);
    }

    private final void I() {
        if (this.f28535c.F() != 4) {
            return;
        }
        lq.a.y(this.f28535c, "Unexpected leading comma", 0, null, 6, null);
        throw new rm.k();
    }

    private final boolean J(hq.e eVar, int i10) {
        String G;
        kq.a aVar = this.f28533a;
        hq.e n10 = eVar.n(i10);
        if (!n10.i() && this.f28535c.N(true)) {
            return true;
        }
        if (!kotlin.jvm.internal.t.b(n10.g(), i.b.f22069a) || ((n10.i() && this.f28535c.N(false)) || (G = this.f28535c.G(this.f28539g.n())) == null || l.f(n10, aVar, G) != -3)) {
            return false;
        }
        this.f28535c.q();
        return true;
    }

    private final int K() {
        boolean M = this.f28535c.M();
        if (!this.f28535c.f()) {
            if (!M) {
                return -1;
            }
            lq.a.y(this.f28535c, "Unexpected trailing comma", 0, null, 6, null);
            throw new rm.k();
        }
        int i10 = this.f28537e;
        if (i10 != -1 && !M) {
            lq.a.y(this.f28535c, "Expected end of the array or comma", 0, null, 6, null);
            throw new rm.k();
        }
        int i11 = i10 + 1;
        this.f28537e = i11;
        return i11;
    }

    private final int L() {
        int i10;
        int i11;
        int i12 = this.f28537e;
        boolean z10 = false;
        boolean z11 = i12 % 2 != 0;
        if (!z11) {
            this.f28535c.n(':');
        } else if (i12 != -1) {
            z10 = this.f28535c.M();
        }
        if (!this.f28535c.f()) {
            if (!z10) {
                return -1;
            }
            lq.a.y(this.f28535c, "Expected '}', but had ',' instead", 0, null, 6, null);
            throw new rm.k();
        }
        if (z11) {
            if (this.f28537e == -1) {
                lq.a aVar = this.f28535c;
                boolean z12 = !z10;
                i11 = aVar.f28498a;
                if (!z12) {
                    lq.a.y(aVar, "Unexpected trailing comma", i11, null, 4, null);
                    throw new rm.k();
                }
            } else {
                lq.a aVar2 = this.f28535c;
                i10 = aVar2.f28498a;
                if (!z10) {
                    lq.a.y(aVar2, "Expected comma after the key-value pair", i10, null, 4, null);
                    throw new rm.k();
                }
            }
        }
        int i13 = this.f28537e + 1;
        this.f28537e = i13;
        return i13;
    }

    private final int M(hq.e eVar) {
        boolean z10;
        boolean M = this.f28535c.M();
        while (this.f28535c.f()) {
            String N = N();
            this.f28535c.n(':');
            int f10 = l.f(eVar, this.f28533a, N);
            boolean z11 = false;
            if (f10 == -3) {
                z11 = true;
                z10 = false;
            } else {
                if (!this.f28539g.d() || !J(eVar, f10)) {
                    h hVar = this.f28540h;
                    if (hVar != null) {
                        hVar.c(f10);
                    }
                    return f10;
                }
                z10 = this.f28535c.M();
            }
            M = z11 ? O(N) : z10;
        }
        if (M) {
            lq.a.y(this.f28535c, "Unexpected trailing comma", 0, null, 6, null);
            throw new rm.k();
        }
        h hVar2 = this.f28540h;
        if (hVar2 != null) {
            return hVar2.d();
        }
        return -1;
    }

    private final String N() {
        return this.f28539g.n() ? this.f28535c.t() : this.f28535c.k();
    }

    private final boolean O(String str) {
        if (this.f28539g.h() || Q(this.f28538f, str)) {
            this.f28535c.I(this.f28539g.n());
        } else {
            this.f28535c.B(str);
        }
        return this.f28535c.M();
    }

    private final void P(hq.e eVar) {
        do {
        } while (F(eVar) != -1);
    }

    private final boolean Q(a aVar, String str) {
        if (aVar == null || !kotlin.jvm.internal.t.b(aVar.f28541a, str)) {
            return false;
        }
        aVar.f28541a = null;
        return true;
    }

    @Override // iq.a, iq.d
    public Object A(fq.a deserializer) {
        boolean U;
        kotlin.jvm.internal.t.g(deserializer, "deserializer");
        try {
            return deserializer.deserialize(this);
        } catch (fq.c e10) {
            String message = e10.getMessage();
            kotlin.jvm.internal.t.d(message);
            U = z.U(message, "at path", false, 2, null);
            if (U) {
                throw e10;
            }
            throw new fq.c(e10.a(), e10.getMessage() + " at path: " + this.f28535c.f28499b.a(), e10);
        }
    }

    @Override // iq.a, iq.d
    public iq.d B(hq.e descriptor) {
        kotlin.jvm.internal.t.g(descriptor, "descriptor");
        return q.a(descriptor) ? new f(this.f28535c, this.f28533a) : super.B(descriptor);
    }

    @Override // iq.a, iq.d
    public short C() {
        long o10 = this.f28535c.o();
        short s10 = (short) o10;
        if (o10 == s10) {
            return s10;
        }
        lq.a.y(this.f28535c, "Failed to parse short for input '" + o10 + '\'', 0, null, 6, null);
        throw new rm.k();
    }

    @Override // iq.a, iq.d
    public float D() {
        lq.a aVar = this.f28535c;
        String s10 = aVar.s();
        try {
            float parseFloat = Float.parseFloat(s10);
            if (!this.f28533a.b().a()) {
                if (!((Float.isInfinite(parseFloat) || Float.isNaN(parseFloat)) ? false : true)) {
                    k.e(this.f28535c, Float.valueOf(parseFloat));
                    throw new rm.k();
                }
            }
            return parseFloat;
        } catch (IllegalArgumentException unused) {
            lq.a.y(aVar, "Failed to parse type 'float' for input '" + s10 + '\'', 0, null, 6, null);
            throw new rm.k();
        }
    }

    @Override // iq.a, iq.d
    public double E() {
        lq.a aVar = this.f28535c;
        String s10 = aVar.s();
        try {
            double parseDouble = Double.parseDouble(s10);
            if (!this.f28533a.b().a()) {
                if (!((Double.isInfinite(parseDouble) || Double.isNaN(parseDouble)) ? false : true)) {
                    k.e(this.f28535c, Double.valueOf(parseDouble));
                    throw new rm.k();
                }
            }
            return parseDouble;
        } catch (IllegalArgumentException unused) {
            lq.a.y(aVar, "Failed to parse type 'double' for input '" + s10 + '\'', 0, null, 6, null);
            throw new rm.k();
        }
    }

    @Override // iq.b
    public int F(hq.e descriptor) {
        kotlin.jvm.internal.t.g(descriptor, "descriptor");
        int i10 = b.f28542a[this.f28534b.ordinal()];
        int K = i10 != 2 ? i10 != 4 ? K() : M(descriptor) : L();
        if (this.f28534b != t.MAP) {
            this.f28535c.f28499b.g(K);
        }
        return K;
    }

    @Override // iq.a, iq.d
    public iq.b a(hq.e descriptor) {
        p pVar;
        kotlin.jvm.internal.t.g(descriptor, "descriptor");
        t b10 = u.b(this.f28533a, descriptor);
        this.f28535c.f28499b.c(descriptor);
        this.f28535c.n(b10.begin);
        I();
        int i10 = b.f28542a[b10.ordinal()];
        if (i10 == 1 || i10 == 2 || i10 == 3) {
            pVar = new p(this.f28533a, b10, this.f28535c, descriptor, this.f28538f);
        } else {
            if (this.f28534b == b10 && this.f28533a.b().g()) {
                return this;
            }
            pVar = new p(this.f28533a, b10, this.f28535c, descriptor, this.f28538f);
        }
        return pVar;
    }

    @Override // iq.a, iq.d
    public boolean b() {
        return this.f28539g.n() ? this.f28535c.i() : this.f28535c.g();
    }

    @Override // iq.a, iq.d
    public char c() {
        String s10 = this.f28535c.s();
        if (s10.length() == 1) {
            return s10.charAt(0);
        }
        lq.a.y(this.f28535c, "Expected single char, but got '" + s10 + '\'', 0, null, 6, null);
        throw new rm.k();
    }

    @Override // kq.f
    public kq.g f() {
        return new n(this.f28533a.b(), this.f28535c).e();
    }

    @Override // iq.a, iq.d
    public int h() {
        long o10 = this.f28535c.o();
        int i10 = (int) o10;
        if (o10 == i10) {
            return i10;
        }
        lq.a.y(this.f28535c, "Failed to parse int for input '" + o10 + '\'', 0, null, 6, null);
        throw new rm.k();
    }

    @Override // iq.a, iq.d
    public Void i() {
        return null;
    }

    @Override // iq.a, iq.d
    public String j() {
        return this.f28539g.n() ? this.f28535c.t() : this.f28535c.q();
    }

    @Override // iq.a, iq.d
    public long o() {
        return this.f28535c.o();
    }

    @Override // iq.a, iq.d
    public boolean p() {
        h hVar = this.f28540h;
        return ((hVar != null ? hVar.b() : false) || lq.a.O(this.f28535c, false, 1, null)) ? false : true;
    }

    @Override // iq.a, iq.b
    public Object s(hq.e descriptor, int i10, fq.a deserializer, Object obj) {
        kotlin.jvm.internal.t.g(descriptor, "descriptor");
        kotlin.jvm.internal.t.g(deserializer, "deserializer");
        boolean z10 = this.f28534b == t.MAP && (i10 & 1) == 0;
        if (z10) {
            this.f28535c.f28499b.d();
        }
        Object s10 = super.s(descriptor, i10, deserializer, obj);
        if (z10) {
            this.f28535c.f28499b.f(s10);
        }
        return s10;
    }

    @Override // iq.a, iq.d
    public int v(hq.e enumDescriptor) {
        kotlin.jvm.internal.t.g(enumDescriptor, "enumDescriptor");
        return l.g(enumDescriptor, this.f28533a, j(), " at path " + this.f28535c.f28499b.a());
    }

    @Override // iq.a, iq.b
    public void w(hq.e descriptor) {
        kotlin.jvm.internal.t.g(descriptor, "descriptor");
        if (this.f28533a.b().h() && descriptor.k() == 0) {
            P(descriptor);
        }
        this.f28535c.n(this.f28534b.end);
        this.f28535c.f28499b.b();
    }

    @Override // iq.a, iq.d
    public byte y() {
        long o10 = this.f28535c.o();
        byte b10 = (byte) o10;
        if (o10 == b10) {
            return b10;
        }
        lq.a.y(this.f28535c, "Failed to parse byte for input '" + o10 + '\'', 0, null, 6, null);
        throw new rm.k();
    }
}
