package m5;

import T0.C0606q;
import com.revenuecat.purchases.subscriberattributes.SubscriberAttributeKt;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import k5.AbstractC2414b;
import k5.B;
import k5.U;
import l5.AbstractC2458c;
import l5.EnumC2456a;
import x4.AbstractC3251q;
import x4.AbstractC3252r;

/* JADX INFO: loaded from: classes3.dex */
public class o implements l5.q, j5.d, j5.b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f21257a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final AbstractC2458c f21258b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final J4.c f21259c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final l5.j f21260d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public String f21261e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public String f21262f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final /* synthetic */ int f21263g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public Object f21264h;

    public o(AbstractC2458c abstractC2458c, J4.c cVar, char c6) {
        this.f21257a = new ArrayList();
        this.f21258b = abstractC2458c;
        this.f21259c = cVar;
        this.f21260d = abstractC2458c.f20333a;
    }

    @Override // j5.b
    public final void A(i5.g descriptor, int i6, String value) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        kotlin.jvm.internal.o.h(value, "value");
        L(J(descriptor, i6), l5.n.b(value));
    }

    @Override // j5.b
    public final void B(i5.g descriptor, int i6, float f6) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        G(J(descriptor, i6), f6);
    }

    @Override // j5.b
    public final void C(U descriptor, int i6, char c6) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        L(J(descriptor, i6), l5.n.b(String.valueOf(c6)));
    }

    @Override // j5.d
    public final void D(long j4) {
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.a(Long.valueOf(j4)));
    }

    @Override // j5.b
    public void E(i5.g descriptor, int i6, g5.a serializer, Object obj) {
        switch (this.f21263g) {
            case 1:
                kotlin.jvm.internal.o.h(descriptor, "descriptor");
                kotlin.jvm.internal.o.h(serializer, "serializer");
                if (obj != null || this.f21260d.f20350b) {
                    o(descriptor, i6, serializer, obj);
                }
                break;
            default:
                o(descriptor, i6, serializer, obj);
                break;
        }
    }

    @Override // j5.d
    public final void F(String value) {
        kotlin.jvm.internal.o.h(value, "value");
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.b(value));
    }

    public final void G(Object obj, float f6) {
        String tag = (String) obj;
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.a(Float.valueOf(f6)));
        this.f21260d.getClass();
        if (Float.isInfinite(f6) || Float.isNaN(f6)) {
            Float fValueOf = Float.valueOf(f6);
            String output = I().toString();
            kotlin.jvm.internal.o.h(output, "output");
            throw new k(l.s(fValueOf, tag, output));
        }
    }

    public final j5.d H(Object obj, i5.g inlineDescriptor) {
        String tag = (String) obj;
        kotlin.jvm.internal.o.h(tag, "tag");
        kotlin.jvm.internal.o.h(inlineDescriptor, "inlineDescriptor");
        if (x.a(inlineDescriptor)) {
            return new b(this, tag);
        }
        if (inlineDescriptor.isInline() && inlineDescriptor.equals(l5.n.f20355a)) {
            return new b(this, tag, inlineDescriptor);
        }
        this.f21257a.add(tag);
        return this;
    }

    public l5.m I() {
        switch (this.f21263g) {
            case 0:
                l5.m mVar = (l5.m) this.f21264h;
                if (mVar != null) {
                    return mVar;
                }
                throw new IllegalArgumentException("Primitive element has not been recorded. Is call to .encodeXxx is missing in serializer?");
            case 1:
                return new l5.y((LinkedHashMap) this.f21264h);
            default:
                return new l5.e((ArrayList) this.f21264h);
        }
    }

    public final String J(i5.g descriptor, int i6) {
        String nestedName;
        kotlin.jvm.internal.o.h(descriptor, "<this>");
        switch (this.f21263g) {
            case 2:
                kotlin.jvm.internal.o.h(descriptor, "descriptor");
                nestedName = String.valueOf(i6);
                break;
            default:
                kotlin.jvm.internal.o.h(descriptor, "descriptor");
                AbstractC2458c json = this.f21258b;
                kotlin.jvm.internal.o.h(json, "json");
                l.n(descriptor, json);
                nestedName = descriptor.g(i6);
                break;
        }
        kotlin.jvm.internal.o.h(nestedName, "nestedName");
        return nestedName;
    }

    public final Object K() {
        ArrayList arrayList = this.f21257a;
        if (arrayList.isEmpty()) {
            throw new g5.f("No tag in stack for requested element");
        }
        return arrayList.remove(AbstractC3252r.A(arrayList));
    }

    public void L(String key, l5.m element) {
        switch (this.f21263g) {
            case 0:
                kotlin.jvm.internal.o.h(key, "key");
                kotlin.jvm.internal.o.h(element, "element");
                if (key != "primitive") {
                    throw new IllegalArgumentException("This output can only consume primitives with 'primitive' tag");
                }
                if (((l5.m) this.f21264h) != null) {
                    throw new IllegalArgumentException("Primitive element was already recorded. Does call to .encodeXxx happen more than once?");
                }
                this.f21264h = element;
                this.f21259c.invoke(element);
                return;
            case 1:
                kotlin.jvm.internal.o.h(key, "key");
                kotlin.jvm.internal.o.h(element, "element");
                ((LinkedHashMap) this.f21264h).put(key, element);
                return;
            default:
                kotlin.jvm.internal.o.h(key, "key");
                kotlin.jvm.internal.o.h(element, "element");
                ((ArrayList) this.f21264h).add(Integer.parseInt(key), element);
                return;
        }
    }

    @Override // j5.d
    public final C0606q a() {
        return this.f21258b.f20334b;
    }

    @Override // j5.d
    public final j5.b b(i5.g descriptor) {
        o oVar;
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        J4.c nodeConsumer = AbstractC3251q.o0(this.f21257a) == null ? this.f21259c : new androidx.compose.runtime.snapshots.e(this, 11);
        W.b bVarE = descriptor.e();
        boolean zC = kotlin.jvm.internal.o.c(bVarE, i5.k.f19101k);
        AbstractC2458c abstractC2458c = this.f21258b;
        if (zC || (bVarE instanceof i5.d)) {
            oVar = new o(abstractC2458c, nodeConsumer, 2);
        } else if (kotlin.jvm.internal.o.c(bVarE, i5.k.l)) {
            i5.g gVarF = l.f(descriptor.i(0), abstractC2458c.f20334b);
            W.b bVarE2 = gVarF.e();
            if (!(bVarE2 instanceof i5.f) && !kotlin.jvm.internal.o.c(bVarE2, i5.j.f19099j)) {
                throw l.b(gVarF);
            }
            kotlin.jvm.internal.o.h(nodeConsumer, "nodeConsumer");
            s sVar = new s(abstractC2458c, nodeConsumer, 1);
            sVar.f21276j = true;
            oVar = sVar;
        } else {
            oVar = new o(abstractC2458c, nodeConsumer, 1);
        }
        String str = this.f21261e;
        if (str != null) {
            if (oVar instanceof s) {
                s sVar2 = (s) oVar;
                sVar2.L(SubscriberAttributeKt.JSON_NAME_KEY, l5.n.b(str));
                String strA = this.f21262f;
                if (strA == null) {
                    strA = descriptor.a();
                }
                sVar2.L("value", l5.n.b(strA));
            } else {
                String strA2 = this.f21262f;
                if (strA2 == null) {
                    strA2 = descriptor.a();
                }
                oVar.L(str, l5.n.b(strA2));
            }
            this.f21261e = null;
            this.f21262f = null;
        }
        return oVar;
    }

    @Override // j5.b
    public final void c(i5.g descriptor) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        if (!this.f21257a.isEmpty()) {
            K();
        }
        this.f21259c.invoke(I());
    }

    @Override // j5.b
    public final void d(U descriptor, int i6, short s6) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        L(J(descriptor, i6), l5.n.a(Short.valueOf(s6)));
    }

    @Override // j5.d
    public final j5.d e(i5.g descriptor) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        if (AbstractC3251q.o0(this.f21257a) == null) {
            return new o(this.f21258b, this.f21259c, 0).e(descriptor);
        }
        if (this.f21261e != null) {
            this.f21262f = descriptor.a();
        }
        return H(K(), descriptor);
    }

    @Override // j5.d
    public final void f() {
        String str = (String) AbstractC3251q.o0(this.f21257a);
        if (str == null) {
            this.f21259c.invoke(l5.v.INSTANCE);
        } else {
            L(str, l5.v.INSTANCE);
        }
    }

    @Override // j5.b
    public final boolean g(i5.g descriptor) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        this.f21260d.getClass();
        return false;
    }

    @Override // j5.d
    public final void h(double d6) {
        t(K(), d6);
    }

    @Override // j5.d
    public final void i(short s6) {
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.a(Short.valueOf(s6)));
    }

    @Override // j5.d
    public final void j(byte b5) {
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.a(Byte.valueOf(b5)));
    }

    @Override // j5.d
    public final void k(boolean z6) {
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        Boolean boolValueOf = Boolean.valueOf(z6);
        B b5 = l5.n.f20355a;
        L(tag, new l5.s(boolValueOf, false, null));
    }

    @Override // j5.b
    public final void l(U descriptor, int i6, byte b5) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        L(J(descriptor, i6), l5.n.a(Byte.valueOf(b5)));
    }

    @Override // j5.d
    public final j5.b m(i5.g descriptor, int i6) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        return b(descriptor);
    }

    @Override // j5.d
    public final void n(float f6) {
        G(K(), f6);
    }

    public final void o(i5.g descriptor, int i6, g5.a serializer, Object obj) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        kotlin.jvm.internal.o.h(serializer, "serializer");
        this.f21257a.add(J(descriptor, i6));
        W.c.C(this, serializer, obj);
    }

    @Override // j5.b
    public final void p(i5.g descriptor, int i6, long j4) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        L(J(descriptor, i6), l5.n.a(Long.valueOf(j4)));
    }

    @Override // j5.d
    public final void q(char c6) {
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.b(String.valueOf(c6)));
    }

    @Override // j5.b
    public final void r(i5.g descriptor, int i6, double d6) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        t(J(descriptor, i6), d6);
    }

    /* JADX WARN: Removed duplicated region for block: B:28:0x006f  */
    @Override // j5.d
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void s(g5.a serializer, Object obj) {
        String strI;
        kotlin.jvm.internal.o.h(serializer, "serializer");
        Object objO0 = AbstractC3251q.o0(this.f21257a);
        AbstractC2458c abstractC2458c = this.f21258b;
        if (objO0 == null) {
            i5.g gVarF = l.f(serializer.getDescriptor(), abstractC2458c.f20334b);
            if ((gVarF.e() instanceof i5.f) || gVarF.e() == i5.j.f19099j) {
                new o(abstractC2458c, this.f21259c, 0).s(serializer, obj);
                return;
            }
        }
        l5.j jVar = abstractC2458c.f20333a;
        boolean z6 = serializer instanceof AbstractC2414b;
        if (z6) {
            strI = jVar.f20354f != EnumC2456a.f20329a ? l.i(serializer.getDescriptor(), abstractC2458c) : null;
        } else {
            int iOrdinal = jVar.f20354f.ordinal();
            if (iOrdinal != 0) {
                if (iOrdinal == 1) {
                    W.b bVarE = serializer.getDescriptor().e();
                    if (kotlin.jvm.internal.o.c(bVarE, i5.k.f19100j) || kotlin.jvm.internal.o.c(bVarE, i5.k.f19102m)) {
                    }
                } else if (iOrdinal != 2) {
                    throw new E3.v();
                }
            }
        }
        if (z6) {
            AbstractC2414b abstractC2414b = (AbstractC2414b) serializer;
            if (obj == null) {
                throw new IllegalArgumentException(("Value for serializer " + abstractC2414b.getDescriptor() + " should always be non-null. Please report issue to the kotlinx.serialization tracker.").toString());
            }
            g5.a aVarF = W.c.F(abstractC2414b, this, obj);
            if (strI != null) {
                l.e(serializer, aVarF, strI);
            }
            l.h(aVarF.getDescriptor().e());
            serializer = aVarF;
        }
        if (strI != null) {
            String strA = serializer.getDescriptor().a();
            this.f21261e = strI;
            this.f21262f = strA;
        }
        serializer.serialize(this, obj);
    }

    public final void t(Object obj, double d6) {
        String tag = (String) obj;
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.a(Double.valueOf(d6)));
        this.f21260d.getClass();
        if (Double.isInfinite(d6) || Double.isNaN(d6)) {
            Double dValueOf = Double.valueOf(d6);
            String output = I().toString();
            kotlin.jvm.internal.o.h(output, "output");
            throw new k(l.s(dValueOf, tag, output));
        }
    }

    @Override // j5.b
    public final j5.d u(U descriptor, int i6) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        return H(J(descriptor, i6), descriptor.i(i6));
    }

    @Override // j5.b
    public final void v(i5.g descriptor, int i6, boolean z6) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        String strJ = J(descriptor, i6);
        Boolean boolValueOf = Boolean.valueOf(z6);
        B b5 = l5.n.f20355a;
        L(strJ, new l5.s(boolValueOf, false, null));
    }

    @Override // j5.b
    public final void w(int i6, int i7, i5.g descriptor) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        L(J(descriptor, i6), l5.n.a(Integer.valueOf(i7)));
    }

    @Override // j5.d
    public final void x(i5.g enumDescriptor, int i6) {
        kotlin.jvm.internal.o.h(enumDescriptor, "enumDescriptor");
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.b(enumDescriptor.g(i6)));
    }

    @Override // j5.d
    public final void y(int i6) {
        String tag = (String) K();
        kotlin.jvm.internal.o.h(tag, "tag");
        L(tag, l5.n.a(Integer.valueOf(i6)));
    }

    @Override // j5.b
    public final void z(i5.g descriptor, int i6, g5.a serializer, Object obj) {
        kotlin.jvm.internal.o.h(descriptor, "descriptor");
        kotlin.jvm.internal.o.h(serializer, "serializer");
        this.f21257a.add(J(descriptor, i6));
        s(serializer, obj);
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public o(AbstractC2458c json, J4.c nodeConsumer, int i6) {
        this(json, nodeConsumer, (char) 0);
        this.f21263g = i6;
        switch (i6) {
            case 1:
                kotlin.jvm.internal.o.h(json, "json");
                kotlin.jvm.internal.o.h(nodeConsumer, "nodeConsumer");
                this(json, nodeConsumer, (char) 0);
                this.f21264h = new LinkedHashMap();
                break;
            case 2:
                kotlin.jvm.internal.o.h(json, "json");
                kotlin.jvm.internal.o.h(nodeConsumer, "nodeConsumer");
                this(json, nodeConsumer, (char) 0);
                this.f21264h = new ArrayList();
                break;
            default:
                kotlin.jvm.internal.o.h(json, "json");
                kotlin.jvm.internal.o.h(nodeConsumer, "nodeConsumer");
                this.f21257a.add("primitive");
                break;
        }
    }
}
