package e.a.r.y;

import e.a.o.j;
import java.lang.annotation.Annotation;

/* JADX INFO: compiled from: Polymorphic.kt */
/* JADX INFO: loaded from: classes.dex */
@d.n
public final class j0 {
    public static final void b(e.a.o.j jVar) {
        d.n0.c.s.e(jVar, "kind");
        if (jVar instanceof j.b) {
            throw new IllegalStateException("Enums cannot be serialized polymorphically with 'type' parameter. You can use 'JsonBuilder.useArrayPolymorphism' instead".toString());
        }
        if (jVar instanceof e.a.o.e) {
            throw new IllegalStateException("Primitives cannot be serialized polymorphically with 'type' parameter. You can use 'JsonBuilder.useArrayPolymorphism' instead".toString());
        }
        if (jVar instanceof e.a.o.d) {
            throw new IllegalStateException("Actual serializer for polymorphic cannot be polymorphic itself".toString());
        }
    }

    public static final String c(e.a.o.f fVar, e.a.r.a aVar) {
        d.n0.c.s.e(fVar, "<this>");
        d.n0.c.s.e(aVar, "json");
        for (Annotation annotation : fVar.f()) {
            if (annotation instanceof e.a.r.e) {
                return ((e.a.r.e) annotation).discriminator();
            }
        }
        return aVar.d().c();
    }

    public static final <T> T d(e.a.r.g gVar, e.a.a<T> aVar) {
        e.a.r.v vVarL;
        d.n0.c.s.e(gVar, "<this>");
        d.n0.c.s.e(aVar, "deserializer");
        if (!(aVar instanceof e.a.q.b) || gVar.d().d().k()) {
            return aVar.deserialize(gVar);
        }
        String strC = c(aVar.getDescriptor(), gVar.d());
        e.a.r.h hVarI = gVar.i();
        e.a.o.f descriptor = aVar.getDescriptor();
        if (hVarI instanceof e.a.r.t) {
            e.a.r.t tVar = (e.a.r.t) hVarI;
            e.a.r.h hVar = (e.a.r.h) tVar.get(strC);
            String strB = (hVar == null || (vVarL = e.a.r.i.l(hVar)) == null) ? null : vVarL.b();
            e.a.a<? extends T> aVarC = ((e.a.q.b) aVar).c(gVar, strB);
            if (aVarC != null) {
                return (T) q0.b(gVar.d(), strC, tVar, aVarC);
            }
            e(strB, tVar);
            throw new d.h();
        }
        throw y.d(-1, "Expected " + d.n0.c.x.b(e.a.r.t.class) + " as the serialized body of " + descriptor.a() + ", but had " + d.n0.c.x.b(hVarI.getClass()));
    }

    public static final Void e(String str, e.a.r.t tVar) {
        String str2;
        d.n0.c.s.e(tVar, "jsonTree");
        if (str == null) {
            str2 = "missing class discriminator ('null')";
        } else {
            str2 = "class discriminator '" + str + '\'';
        }
        throw y.e(-1, "Polymorphic serializer was not found for " + str2, tVar.toString());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void f(e.a.j<?> jVar, e.a.j<Object> jVar2, String str) {
    }
}
