package p138.p395.p396.p397;

import com.squareup.moshi.JsonDataException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
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.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Nullable;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p395.p396.AbstractC6487;
import p138.p395.p396.AbstractC6491;
import p138.p395.p396.C6509;
import p138.p395.p396.InterfaceC6489;

/* JADX INFO: renamed from: ދ.ބ.֏.ޘ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C6527 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final Set<Annotation> f19294 = Collections.emptySet();

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static final Type[] f19295 = new Type[0];

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    @Nullable
    public static final Class<? extends Annotation> f19296;

    /* JADX INFO: renamed from: ދ.ބ.֏.ޘ.ؠ$֏, reason: contains not printable characters */
    public static final class C6528 implements GenericArrayType {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final Type f19297;

        public C6528(Type type) {
            this.f19297 = C6527.m9756(type);
        }

        public boolean equals(Object obj) {
            return (obj instanceof GenericArrayType) && C4303.m7130((Type) this, (Type) obj);
        }

        @Override // java.lang.reflect.GenericArrayType
        public Type getGenericComponentType() {
            return this.f19297;
        }

        public int hashCode() {
            return this.f19297.hashCode();
        }

        public String toString() {
            return C6527.m9764(this.f19297) + "[]";
        }
    }

    /* JADX INFO: renamed from: ދ.ބ.֏.ޘ.ؠ$ؠ, reason: contains not printable characters */
    public static final class C6529 implements ParameterizedType {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        @Nullable
        public final Type f19298;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final Type f19299;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final Type[] f19300;

        public C6529(@Nullable Type type, Type type2, Type... typeArr) {
            if (type2 instanceof Class) {
                Class<?> enclosingClass = ((Class) type2).getEnclosingClass();
                if (type != null) {
                    if (enclosingClass == null || C4303.m7003(type) != enclosingClass) {
                        throw new IllegalArgumentException("unexpected owner type for " + type2 + ": " + type);
                    }
                } else if (enclosingClass != null) {
                    throw new IllegalArgumentException("unexpected owner type for " + type2 + ": null");
                }
            }
            this.f19298 = type == null ? null : C6527.m9756(type);
            this.f19299 = C6527.m9756(type2);
            this.f19300 = (Type[]) typeArr.clone();
            int i = 0;
            while (true) {
                Type[] typeArr2 = this.f19300;
                if (i >= typeArr2.length) {
                    return;
                }
                if (typeArr2[i] == null) {
                    throw null;
                }
                C6527.m9763(typeArr2[i]);
                Type[] typeArr3 = this.f19300;
                typeArr3[i] = C6527.m9756(typeArr3[i]);
                i++;
            }
        }

        public boolean equals(Object obj) {
            return (obj instanceof ParameterizedType) && C4303.m7130((Type) this, (Type) obj);
        }

        @Override // java.lang.reflect.ParameterizedType
        public Type[] getActualTypeArguments() {
            return (Type[]) this.f19300.clone();
        }

        @Override // java.lang.reflect.ParameterizedType
        @Nullable
        public Type getOwnerType() {
            return this.f19298;
        }

        @Override // java.lang.reflect.ParameterizedType
        public Type getRawType() {
            return this.f19299;
        }

        public int hashCode() {
            return (Arrays.hashCode(this.f19300) ^ this.f19299.hashCode()) ^ C6527.m9752((Object) this.f19298);
        }

        public String toString() {
            StringBuilder sb = new StringBuilder((this.f19300.length + 1) * 30);
            sb.append(C6527.m9764(this.f19299));
            if (this.f19300.length == 0) {
                return sb.toString();
            }
            sb.append("<");
            sb.append(C6527.m9764(this.f19300[0]));
            for (int i = 1; i < this.f19300.length; i++) {
                sb.append(", ");
                sb.append(C6527.m9764(this.f19300[i]));
            }
            sb.append(">");
            return sb.toString();
        }
    }

    /* JADX INFO: renamed from: ދ.ބ.֏.ޘ.ؠ$ހ, reason: contains not printable characters */
    public static final class C6530 implements WildcardType {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final Type f19301;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        @Nullable
        public final Type f19302;

        public C6530(Type[] typeArr, Type[] typeArr2) {
            if (typeArr2.length > 1) {
                throw new IllegalArgumentException();
            }
            if (typeArr.length != 1) {
                throw new IllegalArgumentException();
            }
            if (typeArr2.length != 1) {
                if (typeArr[0] == null) {
                    throw null;
                }
                C6527.m9763(typeArr[0]);
                this.f19302 = null;
                this.f19301 = C6527.m9756(typeArr[0]);
                return;
            }
            if (typeArr2[0] == null) {
                throw null;
            }
            C6527.m9763(typeArr2[0]);
            if (typeArr[0] != Object.class) {
                throw new IllegalArgumentException();
            }
            this.f19302 = C6527.m9756(typeArr2[0]);
            this.f19301 = Object.class;
        }

        public boolean equals(Object obj) {
            return (obj instanceof WildcardType) && C4303.m7130((Type) this, (Type) obj);
        }

        @Override // java.lang.reflect.WildcardType
        public Type[] getLowerBounds() {
            Type type = this.f19302;
            return type != null ? new Type[]{type} : C6527.f19295;
        }

        @Override // java.lang.reflect.WildcardType
        public Type[] getUpperBounds() {
            return new Type[]{this.f19301};
        }

        public int hashCode() {
            Type type = this.f19302;
            return (type != null ? type.hashCode() + 31 : 1) ^ (this.f19301.hashCode() + 31);
        }

        public String toString() {
            if (this.f19302 != null) {
                StringBuilder sbM4889 = C2803.m4889("? super ");
                sbM4889.append(C6527.m9764(this.f19302));
                return sbM4889.toString();
            }
            if (this.f19301 == Object.class) {
                return "?";
            }
            StringBuilder sbM48892 = C2803.m4889("? extends ");
            sbM48892.append(C6527.m9764(this.f19301));
            return sbM48892.toString();
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    static {
        Class cls = null;
        try {
            cls = Class.forName("ގ.ނ");
            Class.forName("kotlin.jvm.internal.DefaultConstructorMarker");
        } catch (ClassNotFoundException unused) {
        }
        f19296 = cls;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static int m9752(@Nullable Object obj) {
        if (obj != null) {
            return obj.hashCode();
        }
        return 0;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static JsonDataException m9753(String str, String str2, AbstractC6491 abstractC6491) {
        String strM9690 = abstractC6491.m9690();
        return new JsonDataException(str2.equals(str) ? String.format("Required value '%s' missing at %s", str, strM9690) : String.format("Required value '%s' (JSON name '%s') missing at %s", str, str2, strM9690));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static RuntimeException m9754(InvocationTargetException invocationTargetException) {
        Throwable targetException = invocationTargetException.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw ((RuntimeException) targetException);
        }
        if (targetException instanceof Error) {
            throw ((Error) targetException);
        }
        throw new RuntimeException(targetException);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static String m9755(Type type, Set<? extends Annotation> 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();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Type m9756(Type type) {
        if (type instanceof Class) {
            Class cls = (Class) type;
            return cls.isArray() ? new C6528(m9756((Type) cls.getComponentType())) : cls;
        }
        if (type instanceof ParameterizedType) {
            if (type instanceof C6529) {
                return type;
            }
            ParameterizedType parameterizedType = (ParameterizedType) type;
            return new C6529(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
        }
        if (type instanceof GenericArrayType) {
            return type instanceof C6528 ? type : new C6528(((GenericArrayType) type).getGenericComponentType());
        }
        if (!(type instanceof WildcardType) || (type instanceof C6530)) {
            return type;
        }
        WildcardType wildcardType = (WildcardType) type;
        return new C6530(wildcardType.getUpperBounds(), wildcardType.getLowerBounds());
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Type m9757(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++) {
                if (interfaces[i] == cls2) {
                    return cls.getGenericInterfaces()[i];
                }
                if (cls2.isAssignableFrom(interfaces[i])) {
                    return m9757(cls.getGenericInterfaces()[i], interfaces[i], cls2);
                }
            }
        }
        if (!cls.isInterface()) {
            while (cls != Object.class) {
                Class<? super Object> superclass = cls.getSuperclass();
                if (superclass == cls2) {
                    return cls.getGenericSuperclass();
                }
                if (cls2.isAssignableFrom(superclass)) {
                    return m9757(cls.getGenericSuperclass(), (Class<?>) superclass, cls2);
                }
                cls = superclass;
            }
        }
        return cls2;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Type m9758(Type type, Class<?> cls, Type type2) {
        return m9759(type, cls, type2, new LinkedHashSet());
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x004a  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Type m9759(Type type, Class<?> cls, Type type2, Collection<TypeVariable> collection) {
        TypeVariable typeVariable;
        do {
            int i = 0;
            if (!(type2 instanceof TypeVariable)) {
                if (type2 instanceof Class) {
                    Class cls2 = (Class) type2;
                    if (cls2.isArray()) {
                        Class<?> componentType = cls2.getComponentType();
                        Type typeM9759 = m9759(type, cls, componentType, collection);
                        return componentType == typeM9759 ? cls2 : new C6528(typeM9759);
                    }
                }
                if (type2 instanceof GenericArrayType) {
                    GenericArrayType genericArrayType = (GenericArrayType) type2;
                    Type genericComponentType = genericArrayType.getGenericComponentType();
                    Type typeM97592 = m9759(type, cls, genericComponentType, collection);
                    return genericComponentType == typeM97592 ? genericArrayType : new C6528(typeM97592);
                }
                if (type2 instanceof ParameterizedType) {
                    ParameterizedType parameterizedType = (ParameterizedType) type2;
                    Type ownerType = parameterizedType.getOwnerType();
                    Type typeM97593 = m9759(type, cls, ownerType, collection);
                    boolean z = typeM97593 != ownerType;
                    Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
                    int length = actualTypeArguments.length;
                    while (i < length) {
                        Type typeM97594 = m9759(type, cls, actualTypeArguments[i], collection);
                        if (typeM97594 != actualTypeArguments[i]) {
                            if (!z) {
                                actualTypeArguments = (Type[]) actualTypeArguments.clone();
                                z = true;
                            }
                            actualTypeArguments[i] = typeM97594;
                        }
                        i++;
                    }
                    return z ? new C6529(typeM97593, parameterizedType.getRawType(), actualTypeArguments) : parameterizedType;
                }
                boolean z2 = type2 instanceof WildcardType;
                Type type3 = type2;
                if (z2) {
                    WildcardType wildcardType = (WildcardType) type2;
                    Type[] lowerBounds = wildcardType.getLowerBounds();
                    Type[] upperBounds = wildcardType.getUpperBounds();
                    if (lowerBounds.length == 1) {
                        Type typeM97595 = m9759(type, cls, lowerBounds[0], collection);
                        type3 = wildcardType;
                        if (typeM97595 != lowerBounds[0]) {
                            return new C6530(new Type[]{Object.class}, typeM97595 instanceof WildcardType ? ((WildcardType) typeM97595).getLowerBounds() : new Type[]{typeM97595});
                        }
                    } else {
                        type3 = wildcardType;
                        if (upperBounds.length == 1) {
                            Type typeM97596 = m9759(type, cls, upperBounds[0], collection);
                            type3 = wildcardType;
                            if (typeM97596 != upperBounds[0]) {
                                return new C6530(typeM97596 instanceof WildcardType ? ((WildcardType) typeM97596).getUpperBounds() : new Type[]{typeM97596}, f19295);
                            }
                        }
                    }
                }
                return type3;
            }
            typeVariable = (TypeVariable) type2;
            if (collection.contains(typeVariable)) {
                return type2;
            }
            collection.add(typeVariable);
            GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
            Class cls3 = genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
            if (cls3 == null) {
                type2 = typeVariable;
            } else {
                Type typeM9757 = m9757(type, cls, (Class<?>) cls3);
                if (typeM9757 instanceof ParameterizedType) {
                    TypeVariable[] typeParameters = cls3.getTypeParameters();
                    while (i < typeParameters.length) {
                        if (typeVariable.equals(typeParameters[i])) {
                            type2 = ((ParameterizedType) typeM9757).getActualTypeArguments()[i];
                        } else {
                            i++;
                        }
                    }
                    throw new NoSuchElementException();
                }
            }
        } while (type2 != typeVariable);
        return type2;
    }

    @Nullable
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static AbstractC6487<?> m9760(C6509 c6509, Type type, Class<?> cls) {
        Constructor<?> declaredConstructor;
        Object[] objArr;
        InterfaceC6489 interfaceC6489 = (InterfaceC6489) cls.getAnnotation(InterfaceC6489.class);
        if (interfaceC6489 == null || !interfaceC6489.generateAdapter()) {
            return null;
        }
        try {
            try {
                Class<?> cls2 = Class.forName(cls.getName().replace("$", "_") + "JsonAdapter", true, cls.getClassLoader());
                if (type instanceof ParameterizedType) {
                    Type[] actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments();
                    try {
                        declaredConstructor = cls2.getDeclaredConstructor(C6509.class, Type[].class);
                        objArr = new Object[]{c6509, actualTypeArguments};
                    } catch (NoSuchMethodException unused) {
                        declaredConstructor = cls2.getDeclaredConstructor(Type[].class);
                        objArr = new Object[]{actualTypeArguments};
                    }
                } else {
                    try {
                        declaredConstructor = cls2.getDeclaredConstructor(C6509.class);
                        objArr = new Object[]{c6509};
                    } catch (NoSuchMethodException unused2) {
                        declaredConstructor = cls2.getDeclaredConstructor(new Class[0]);
                        objArr = new Object[0];
                    }
                }
                declaredConstructor.setAccessible(true);
                return ((AbstractC6487) declaredConstructor.newInstance(objArr)).m9682();
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(C2803.m4878("Failed to find the generated JsonAdapter constructor for ", cls), e);
            }
        } catch (ClassNotFoundException e2) {
            throw new RuntimeException(C2803.m4878("Failed to find the generated JsonAdapter class for ", cls), e2);
        } catch (IllegalAccessException e3) {
            throw new RuntimeException(C2803.m4878("Failed to access the generated JsonAdapter for ", cls), e3);
        } catch (InstantiationException e4) {
            throw new RuntimeException(C2803.m4878("Failed to instantiate the generated JsonAdapter for ", cls), e4);
        } catch (InvocationTargetException e5) {
            m9754(e5);
            throw null;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static boolean m9761(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.");
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static JsonDataException m9762(String str, String str2, AbstractC6491 abstractC6491) {
        String strM9690 = abstractC6491.m9690();
        return new JsonDataException(str2.equals(str) ? String.format("Non-null value '%s' was null at %s", str, strM9690) : String.format("Non-null value '%s' (JSON name '%s') was null at %s", str, str2, strM9690));
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static void m9763(Type type) {
        if ((type instanceof Class) && ((Class) type).isPrimitive()) {
            throw new IllegalArgumentException("Unexpected primitive " + type + ". Use the boxed type.");
        }
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static String m9764(Type type) {
        return type instanceof Class ? ((Class) type).getName() : type.toString();
    }
}
