package p6;

import java.lang.reflect.GenericArrayType;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.NoSuchElementException;
import java.util.Set;
import kotlin.jvm.internal.DefaultConstructorMarker;
import o6.AbstractC1394n;

/* JADX INFO: renamed from: p6.e, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC1439e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final Set f16150a = Collections.EMPTY_SET;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Type[] f16151b = new Type[0];

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Class f16152c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final Class f16153d;

    static {
        Class<?> cls;
        try {
            cls = Class.forName(getKotlinMetadataClassName());
        } catch (ClassNotFoundException unused) {
            cls = null;
        }
        f16153d = cls;
        f16152c = DefaultConstructorMarker.class;
        LinkedHashMap linkedHashMap = new LinkedHashMap(16);
        linkedHashMap.put(Boolean.TYPE, Boolean.class);
        linkedHashMap.put(Byte.TYPE, Byte.class);
        linkedHashMap.put(Character.TYPE, Character.class);
        linkedHashMap.put(Double.TYPE, Double.class);
        linkedHashMap.put(Float.TYPE, Float.class);
        linkedHashMap.put(Integer.TYPE, Integer.class);
        linkedHashMap.put(Long.TYPE, Long.class);
        linkedHashMap.put(Short.TYPE, Short.class);
        linkedHashMap.put(Void.TYPE, Void.class);
        Collections.unmodifiableMap(linkedHashMap);
    }

    public static Type a(Type type) {
        if (type instanceof Class) {
            Class cls = (Class) type;
            return cls.isArray() ? new C1436b(a(cls.getComponentType())) : cls;
        }
        if (type instanceof ParameterizedType) {
            if (type instanceof C1437c) {
                return type;
            }
            ParameterizedType parameterizedType = (ParameterizedType) type;
            return new C1437c(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
        }
        if (type instanceof GenericArrayType) {
            return type instanceof C1436b ? type : new C1436b(((GenericArrayType) type).getGenericComponentType());
        }
        if (!(type instanceof WildcardType) || (type instanceof C1438d)) {
            return type;
        }
        WildcardType wildcardType = (WildcardType) type;
        return new C1438d(wildcardType.getUpperBounds(), wildcardType.getLowerBounds());
    }

    public static void b(Type type) {
        if ((type instanceof Class) && ((Class) type).isPrimitive()) {
            throw new IllegalArgumentException("Unexpected primitive " + type + ". Use the boxed type.");
        }
    }

    public static Type c(Type type, Class cls, Class cls2) {
        if (cls2 == cls) {
            return type;
        }
        if (cls2.isInterface()) {
            Class<?>[] interfaces = cls.getInterfaces();
            int length = interfaces.length;
            for (int i = 0; i < length; i++) {
                Class<?> cls3 = interfaces[i];
                if (cls3 == cls2) {
                    return cls.getGenericInterfaces()[i];
                }
                if (cls2.isAssignableFrom(cls3)) {
                    return c(cls.getGenericInterfaces()[i], interfaces[i], cls2);
                }
            }
        }
        if (!cls.isInterface()) {
            while (cls != Object.class) {
                Class<?> superclass = cls.getSuperclass();
                if (superclass == cls2) {
                    return cls.getGenericSuperclass();
                }
                if (cls2.isAssignableFrom(superclass)) {
                    return c(cls.getGenericSuperclass(), superclass, cls2);
                }
                cls = superclass;
            }
        }
        return cls2;
    }

    public static boolean d(Class cls) {
        String name = cls.getName();
        return name.startsWith("android.") || name.startsWith("androidx.") || name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("kotlin.") || name.startsWith("kotlinx.") || name.startsWith("scala.");
    }

    public static A6.b e(String str, String str2, AbstractC1394n abstractC1394n) {
        String str3;
        String strM = abstractC1394n.m();
        if (str2.equals(str)) {
            str3 = "Required value '" + str + "' missing at " + strM;
        } else {
            str3 = "Required value '" + str + "' (JSON name '" + str2 + "') missing at " + strM;
        }
        return new A6.b(str3);
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x004b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Type f(Type type, Class cls, Type type2, LinkedHashSet linkedHashSet) {
        while (type2 instanceof TypeVariable) {
            TypeVariable typeVariable = (TypeVariable) type2;
            if (linkedHashSet.contains(typeVariable)) {
                return type2;
            }
            linkedHashSet.add(typeVariable);
            GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
            Class cls2 = genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
            if (cls2 == null) {
                type2 = typeVariable;
            } else {
                Type typeC = c(type, cls, cls2);
                if (typeC instanceof ParameterizedType) {
                    TypeVariable[] typeParameters = cls2.getTypeParameters();
                    for (int i = 0; i < typeParameters.length; i++) {
                        if (typeVariable.equals(typeParameters[i])) {
                            type2 = ((ParameterizedType) typeC).getActualTypeArguments()[i];
                        }
                    }
                    throw new NoSuchElementException();
                }
            }
            if (type2 == typeVariable) {
                return type2;
            }
        }
        if (type2 instanceof Class) {
            Class cls3 = (Class) type2;
            if (cls3.isArray()) {
                Class<?> componentType = cls3.getComponentType();
                Type typeF = f(type, cls, componentType, linkedHashSet);
                return componentType == typeF ? cls3 : new C1436b(typeF);
            }
        }
        if (type2 instanceof GenericArrayType) {
            GenericArrayType genericArrayType = (GenericArrayType) type2;
            Type genericComponentType = genericArrayType.getGenericComponentType();
            Type typeF2 = f(type, cls, genericComponentType, linkedHashSet);
            return genericComponentType == typeF2 ? genericArrayType : new C1436b(typeF2);
        }
        if (type2 instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type2;
            Type ownerType = parameterizedType.getOwnerType();
            Type typeF3 = f(type, cls, ownerType, linkedHashSet);
            boolean z8 = typeF3 != ownerType;
            Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
            int length = actualTypeArguments.length;
            for (int i5 = 0; i5 < length; i5++) {
                Type typeF4 = f(type, cls, actualTypeArguments[i5], linkedHashSet);
                if (typeF4 != actualTypeArguments[i5]) {
                    if (!z8) {
                        actualTypeArguments = (Type[]) actualTypeArguments.clone();
                        z8 = true;
                    }
                    actualTypeArguments[i5] = typeF4;
                }
            }
            return z8 ? new C1437c(typeF3, parameterizedType.getRawType(), actualTypeArguments) : parameterizedType;
        }
        boolean z9 = type2 instanceof WildcardType;
        Type type3 = type2;
        if (z9) {
            WildcardType wildcardType = (WildcardType) type2;
            Type[] lowerBounds = wildcardType.getLowerBounds();
            Type[] upperBounds = wildcardType.getUpperBounds();
            if (lowerBounds.length == 1) {
                Type typeF5 = f(type, cls, lowerBounds[0], linkedHashSet);
                type3 = wildcardType;
                if (typeF5 != lowerBounds[0]) {
                    return new C1438d(new Type[]{Object.class}, typeF5 instanceof WildcardType ? ((WildcardType) typeF5).getLowerBounds() : new Type[]{typeF5});
                }
            } else {
                type3 = wildcardType;
                if (upperBounds.length == 1) {
                    Type typeF6 = f(type, cls, upperBounds[0], linkedHashSet);
                    type3 = wildcardType;
                    if (typeF6 != upperBounds[0]) {
                        return new C1438d(typeF6 instanceof WildcardType ? ((WildcardType) typeF6).getUpperBounds() : new Type[]{typeF6}, f16151b);
                    }
                }
            }
        }
        return type3;
    }

    public static void g(InvocationTargetException invocationTargetException) {
        Throwable targetException = invocationTargetException.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw ((RuntimeException) targetException);
        }
        if (!(targetException instanceof Error)) {
            throw new RuntimeException(targetException);
        }
        throw ((Error) targetException);
    }

    private static String getKotlinMetadataClassName() {
        return "kotlin.Metadata";
    }

    public static String h(Type type, Set set) {
        String str;
        StringBuilder sb = new StringBuilder();
        sb.append(type);
        if (set.isEmpty()) {
            str = " (with no annotations)";
        } else {
            str = " annotated " + set;
        }
        sb.append(str);
        return sb.toString();
    }

    public static String i(Type type) {
        return type instanceof Class ? ((Class) type).getName() : type.toString();
    }

    public static A6.b j(String str, String str2, AbstractC1394n abstractC1394n) {
        String str3;
        String strM = abstractC1394n.m();
        if (str2.equals(str)) {
            str3 = "Non-null value '" + str + "' was null at " + strM;
        } else {
            str3 = "Non-null value '" + str + "' (JSON name '" + str2 + "') was null at " + strM;
        }
        return new A6.b(str3);
    }
}
