package k.a.q.y;

import java.lang.annotation.Annotation;
import k.a.n.j;

/* JADX INFO: compiled from: Polymorphic.kt */
/* JADX INFO: loaded from: classes.dex */
public final class b0 {
    public static final void b(k.a.n.j jVar) {
        j.p0.d.r.f(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 k.a.n.e) {
            throw new IllegalStateException("Primitives cannot be serialized polymorphically with 'type' parameter. You can use 'JsonBuilder.useArrayPolymorphism' instead".toString());
        }
        if (jVar instanceof k.a.n.d) {
            throw new IllegalStateException("Actual serializer for polymorphic cannot be polymorphic itself".toString());
        }
    }

    public static final String c(k.a.n.f fVar, k.a.q.a aVar) {
        j.p0.d.r.f(fVar, "<this>");
        j.p0.d.r.f(aVar, "json");
        for (Annotation annotation : fVar.getAnnotations()) {
            if (annotation instanceof k.a.q.e) {
                return ((k.a.q.e) annotation).discriminator();
            }
        }
        return aVar.d().c();
    }

    public static final <T> T d(k.a.q.g gVar, k.a.a<T> aVar) {
        k.a.q.v vVarL;
        j.p0.d.r.f(gVar, "<this>");
        j.p0.d.r.f(aVar, "deserializer");
        if (!(aVar instanceof k.a.p.b) || gVar.c().d().k()) {
            return aVar.d(gVar);
        }
        String strC = c(aVar.a(), gVar.c());
        k.a.q.h hVarV = gVar.v();
        k.a.n.f fVarA = aVar.a();
        if (hVarV instanceof k.a.q.t) {
            k.a.q.t tVar = (k.a.q.t) hVarV;
            k.a.q.h hVar = (k.a.q.h) tVar.get(strC);
            String strB = (hVar == null || (vVarL = k.a.q.i.l(hVar)) == null) ? null : vVarL.b();
            k.a.a<? extends T> aVarH = ((k.a.p.b) aVar).h(gVar, strB);
            if (aVarH != null) {
                return (T) i0.b(gVar.c(), strC, tVar, aVarH);
            }
            e(strB, tVar);
            throw null;
        }
        throw q.d(-1, "Expected " + j.p0.d.d0.b(k.a.q.t.class) + " as the serialized body of " + fVarA.b() + ", but had " + j.p0.d.d0.b(hVarV.getClass()));
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public static final void f(k.a.i<?> iVar, k.a.i<Object> iVar2, String str) {
    }
}
