package k.a.r;

import j.p0.c.l;
import j.p0.d.d0;
import j.p0.d.h0;
import j.p0.d.r;
import java.util.List;
import java.util.Map;
import k.a.i;
import k.a.p.a1;
import k.a.r.a;

/* JADX INFO: compiled from: SerializersModule.kt */
/* JADX INFO: loaded from: classes.dex */
public final class b extends c {
    private final Map<j.s0.c<?>, a> a;
    public final Map<j.s0.c<?>, Map<j.s0.c<?>, k.a.b<?>>> b;
    private final Map<j.s0.c<?>, l<?, i<?>>> c;
    private final Map<j.s0.c<?>, Map<String, k.a.b<?>>> d;
    private final Map<j.s0.c<?>, l<String, k.a.a<?>>> e;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    /* JADX WARN: Multi-variable type inference failed */
    public b(Map<j.s0.c<?>, ? extends a> map, Map<j.s0.c<?>, ? extends Map<j.s0.c<?>, ? extends k.a.b<?>>> map2, Map<j.s0.c<?>, ? extends l<?, ? extends i<?>>> map3, Map<j.s0.c<?>, ? extends Map<String, ? extends k.a.b<?>>> map4, Map<j.s0.c<?>, ? extends l<? super String, ? extends k.a.a<?>>> map5) {
        super(null);
        r.f(map, "class2ContextualFactory");
        r.f(map2, "polyBase2Serializers");
        r.f(map3, "polyBase2DefaultSerializerProvider");
        r.f(map4, "polyBase2NamedSerializers");
        r.f(map5, "polyBase2DefaultDeserializerProvider");
        this.a = map;
        this.b = map2;
        this.c = map3;
        this.d = map4;
        this.e = map5;
    }

    @Override // k.a.r.c
    public void a(e eVar) {
        r.f(eVar, "collector");
        for (Map.Entry<j.s0.c<?>, a> entry : this.a.entrySet()) {
            j.s0.c<?> key = entry.getKey();
            a value = entry.getValue();
            if (value instanceof a.C0092a) {
                r.d(key, "null cannot be cast to non-null type kotlin.reflect.KClass<kotlin.Any>");
                k.a.b<?> bVarB = ((a.C0092a) value).b();
                r.d(bVarB, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<kotlin.Any>");
                eVar.c(key, bVarB);
            } else if (value instanceof a.b) {
                eVar.d(key, ((a.b) value).b());
            }
        }
        for (Map.Entry<j.s0.c<?>, Map<j.s0.c<?>, k.a.b<?>>> entry2 : this.b.entrySet()) {
            j.s0.c<?> key2 = entry2.getKey();
            for (Map.Entry<j.s0.c<?>, k.a.b<?>> entry3 : entry2.getValue().entrySet()) {
                j.s0.c<?> key3 = entry3.getKey();
                k.a.b<?> value2 = entry3.getValue();
                r.d(key2, "null cannot be cast to non-null type kotlin.reflect.KClass<kotlin.Any>");
                r.d(key3, "null cannot be cast to non-null type kotlin.reflect.KClass<kotlin.Any>");
                r.d(value2, "null cannot be cast to non-null type kotlinx.serialization.KSerializer<T of kotlinx.serialization.internal.Platform_commonKt.cast>");
                eVar.a(key2, key3, value2);
            }
        }
        for (Map.Entry<j.s0.c<?>, l<?, i<?>>> entry4 : this.c.entrySet()) {
            j.s0.c<?> key4 = entry4.getKey();
            l<?, i<?>> value3 = entry4.getValue();
            r.d(key4, "null cannot be cast to non-null type kotlin.reflect.KClass<kotlin.Any>");
            r.d(value3, "null cannot be cast to non-null type kotlin.Function1<@[ParameterName(name = 'value')] kotlin.Any, kotlinx.serialization.SerializationStrategy<kotlin.Any>?>{ kotlinx.serialization.modules.SerializersModuleKt.PolymorphicSerializerProvider<kotlin.Any> }");
            h0.b(value3, 1);
            eVar.e(key4, value3);
        }
        for (Map.Entry<j.s0.c<?>, l<String, k.a.a<?>>> entry5 : this.e.entrySet()) {
            j.s0.c<?> key5 = entry5.getKey();
            l<String, k.a.a<?>> value4 = entry5.getValue();
            r.d(key5, "null cannot be cast to non-null type kotlin.reflect.KClass<kotlin.Any>");
            r.d(value4, "null cannot be cast to non-null type kotlin.Function1<@[ParameterName(name = 'className')] kotlin.String?, kotlinx.serialization.DeserializationStrategy<out kotlin.Any>?>{ kotlinx.serialization.modules.SerializersModuleKt.PolymorphicDeserializerProvider<out kotlin.Any> }");
            h0.b(value4, 1);
            eVar.b(key5, value4);
        }
    }

    @Override // k.a.r.c
    public <T> k.a.b<T> b(j.s0.c<T> cVar, List<? extends k.a.b<?>> list) {
        r.f(cVar, "kClass");
        r.f(list, "typeArgumentsSerializers");
        a aVar = this.a.get(cVar);
        k.a.b<?> bVarA = aVar != null ? aVar.a(list) : null;
        if (bVarA instanceof k.a.b) {
            return (k.a.b<T>) bVarA;
        }
        return null;
    }

    @Override // k.a.r.c
    public <T> k.a.a<? extends T> d(j.s0.c<? super T> cVar, String str) {
        r.f(cVar, "baseClass");
        Map<String, k.a.b<?>> map = this.d.get(cVar);
        k.a.b<?> bVar = map != null ? map.get(str) : null;
        if (!(bVar instanceof k.a.b)) {
            bVar = null;
        }
        if (bVar != null) {
            return bVar;
        }
        l<String, k.a.a<?>> lVar = this.e.get(cVar);
        l<String, k.a.a<?>> lVar2 = h0.e(lVar, 1) ? lVar : null;
        if (lVar2 != null) {
            return (k.a.a) lVar2.invoke(str);
        }
        return null;
    }

    @Override // k.a.r.c
    public <T> i<T> e(j.s0.c<? super T> cVar, T t) {
        r.f(cVar, "baseClass");
        r.f(t, "value");
        if (!a1.g(t, cVar)) {
            return null;
        }
        Map<j.s0.c<?>, k.a.b<?>> map = this.b.get(cVar);
        k.a.b<?> bVar = map != null ? map.get(d0.b(t.getClass())) : null;
        if (!(bVar instanceof i)) {
            bVar = null;
        }
        if (bVar != null) {
            return bVar;
        }
        l<?, i<?>> lVar = this.c.get(cVar);
        l<?, i<?>> lVar2 = h0.e(lVar, 1) ? lVar : null;
        if (lVar2 != null) {
            return (i) lVar2.invoke(t);
        }
        return null;
    }
}
