package defpackage;

import j$.util.DesugarCollections;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;

/* JADX INFO: renamed from: ᵦᵧʼᵤ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3596 implements InterfaceC5294 {

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final /* synthetic */ int f13701;

    public /* synthetic */ C3596(int i) {
        this.f13701 = i;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static void m8125(Type type, Class cls) {
        Class<?> cls2 = ᵥˈᵛ.ˁˌᵩ(type);
        if (cls.isAssignableFrom(cls2)) {
            StringBuilder sb = new StringBuilder("No JsonAdapter for ");
            sb.append(type);
            String simpleName = cls.getSimpleName();
            String simpleName2 = cls2.getSimpleName();
            sb.append(", you should probably use ");
            sb.append(simpleName);
            sb.append(" instead of ");
            sb.append(simpleName2);
            sb.append(" (Moshi only supports the collection interfaces by default) or else register a custom JsonAdapter.");
            throw new IllegalArgumentException(sb.toString());
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:143:0x0266  */
    @Override // defpackage.InterfaceC5294
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final AbstractC3610 mo8126(Type type, Set set, C5185 c5185) {
        AbstractC3610 abstractC3610;
        int i;
        ᵗʓ c2868;
        Class cls;
        boolean z;
        Field[] fieldArr;
        boolean z2;
        LinkedHashSet linkedHashSet;
        InterfaceC2311 interfaceC2311;
        Class cls2;
        Type[] actualTypeArguments;
        char c;
        C2807 c2807M8143;
        Class<?> cls3;
        Constructor<?> declaredConstructor;
        Object[] objArr;
        Type typeM9584 = type;
        int i2 = this.f13701;
        Class cls4 = Integer.TYPE;
        boolean z3 = true;
        LinkedHashSet linkedHashSet2 = null;
        switch (i2) {
            case 0:
                Type genericComponentType = typeM9584 instanceof GenericArrayType ? ((GenericArrayType) typeM9584).getGenericComponentType() : typeM9584 instanceof Class ? ((Class) typeM9584).getComponentType() : null;
                if (genericComponentType != null && set.isEmpty()) {
                    return new ˊʧʘ(ᵥˈᵛ.ˁˌᵩ(genericComponentType), c5185.m10734(genericComponentType, AbstractC4534.f17254, null)).m8143();
                }
                return null;
            case 1:
                if ((typeM9584 instanceof Class) || (typeM9584 instanceof ParameterizedType)) {
                    Class cls5 = ᵥˈᵛ.ˁˌᵩ(typeM9584);
                    if (!cls5.isInterface() && !cls5.isEnum() && set.isEmpty()) {
                        if (AbstractC4534.m9582(cls5)) {
                            m8125(typeM9584, List.class);
                            m8125(typeM9584, Set.class);
                            m8125(typeM9584, Map.class);
                            m8125(typeM9584, Collection.class);
                            String str = "Platform " + cls5;
                            if (typeM9584 instanceof ParameterizedType) {
                                str = str + " in " + typeM9584;
                            }
                            ᵕᵩʽᵲ.ᵮᵣᵗˈ(str.concat(" requires explicit JsonAdapter to be registered"));
                            return null;
                        }
                        if (cls5.isAnonymousClass()) {
                            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Cannot serialize anonymous class ".concat(cls5.getName()));
                            return null;
                        }
                        if (cls5.isLocalClass()) {
                            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Cannot serialize local class ".concat(cls5.getName()));
                            return null;
                        }
                        if (cls5.getEnclosingClass() != null && !Modifier.isStatic(cls5.getModifiers())) {
                            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Cannot serialize non-static nested class ".concat(cls5.getName()));
                            return null;
                        }
                        if (Modifier.isAbstract(cls5.getModifiers())) {
                            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Cannot serialize abstract class ".concat(cls5.getName()));
                            return null;
                        }
                        Class<? extends Annotation> cls6 = AbstractC4534.f17253;
                        if (cls6 != null && cls5.isAnnotationPresent(cls6)) {
                            C3226.m7372("Cannot serialize Kotlin type ", cls5.getName(), ". Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapterFactory from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.");
                            return null;
                        }
                        try {
                            try {
                                try {
                                    try {
                                        Constructor declaredConstructor2 = cls5.getDeclaredConstructor(null);
                                        declaredConstructor2.setAccessible(true);
                                        c2868 = new C2868(declaredConstructor2, cls5);
                                    } catch (Exception unused) {
                                        abstractC3610 = null;
                                        ᵕᵩʽᵲ.ᵮᵣᵗˈ("cannot construct instances of ".concat(cls5.getName()));
                                    }
                                } catch (NoSuchMethodException unused2) {
                                    Class<?> cls7 = Class.forName("sun.misc.Unsafe");
                                    Field declaredField = cls7.getDeclaredField("theUnsafe");
                                    declaredField.setAccessible(true);
                                    c2868 = new C5470(cls7.getMethod("allocateInstance", Class.class), declaredField.get(null), cls5);
                                }
                            } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException unused3) {
                                Method declaredMethod = ObjectStreamClass.class.getDeclaredMethod("getConstructorId", Class.class);
                                declaredMethod.setAccessible(true);
                                int iIntValue = ((Integer) declaredMethod.invoke(null, Object.class)).intValue();
                                Method declaredMethod2 = ObjectStreamClass.class.getDeclaredMethod("newInstance", Class.class, cls4);
                                declaredMethod2.setAccessible(true);
                                c2868 = new C0404(declaredMethod2, cls5, iIntValue);
                            } catch (IllegalAccessException unused4) {
                                throw new AssertionError();
                            }
                            i = 0;
                            break;
                        } catch (IllegalAccessException unused5) {
                            throw new AssertionError();
                        } catch (NoSuchMethodException unused6) {
                            i = 0;
                            Method declaredMethod3 = ObjectInputStream.class.getDeclaredMethod("newInstance", Class.class, Class.class);
                            declaredMethod3.setAccessible(true);
                            c2868 = new C2868(declaredMethod3, cls5);
                            break;
                        } catch (InvocationTargetException e) {
                            AbstractC4534.m9581(e);
                            throw null;
                        }
                        TreeMap treeMap = new TreeMap();
                        while (typeM9584 != Object.class) {
                            Class cls8 = ᵥˈᵛ.ˁˌᵩ(typeM9584);
                            boolean zM9582 = AbstractC4534.m9582(cls8);
                            Field[] declaredFields = cls8.getDeclaredFields();
                            int length = declaredFields.length;
                            int i3 = i;
                            while (i3 < length) {
                                Field field = declaredFields[i3];
                                int modifiers = field.getModifiers();
                                if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || (!(Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || !zM9582) || ((interfaceC2311 = (InterfaceC2311) field.getAnnotation(InterfaceC2311.class)) != null && interfaceC2311.ignore()))) {
                                    cls = cls8;
                                    z = zM9582;
                                    fieldArr = declaredFields;
                                    z2 = z3;
                                    linkedHashSet = linkedHashSet2;
                                } else {
                                    Type typeM95842 = AbstractC4534.m9584(typeM9584, cls8, field.getGenericType(), new LinkedHashSet());
                                    Annotation[] annotations = field.getAnnotations();
                                    linkedHashSet = linkedHashSet2;
                                    int length2 = annotations.length;
                                    LinkedHashSet linkedHashSet3 = linkedHashSet;
                                    int i4 = 0;
                                    while (i4 < length2) {
                                        Class cls9 = cls8;
                                        Annotation annotation = annotations[i4];
                                        boolean z4 = zM9582;
                                        Field[] fieldArr2 = declaredFields;
                                        if (annotation.annotationType().isAnnotationPresent(InterfaceC1062.class)) {
                                            LinkedHashSet linkedHashSet4 = linkedHashSet3 == null ? new LinkedHashSet() : linkedHashSet3;
                                            linkedHashSet4.add(annotation);
                                            linkedHashSet3 = linkedHashSet4;
                                        }
                                        i4++;
                                        cls8 = cls9;
                                        zM9582 = z4;
                                        declaredFields = fieldArr2;
                                    }
                                    cls = cls8;
                                    z = zM9582;
                                    fieldArr = declaredFields;
                                    Set setUnmodifiableSet = linkedHashSet3 != null ? DesugarCollections.unmodifiableSet(linkedHashSet3) : AbstractC4534.f17254;
                                    String name = field.getName();
                                    AbstractC3610 abstractC3610M10734 = c5185.m10734(typeM95842, setUnmodifiableSet, name);
                                    z2 = true;
                                    field.setAccessible(true);
                                    if (interfaceC2311 != null) {
                                        String strName = interfaceC2311.name();
                                        if (!"\u0000".equals(strName)) {
                                            name = strName;
                                        }
                                    }
                                    C0200 c0200 = (C0200) treeMap.put(name, new C0200(name, field, abstractC3610M10734));
                                    if (c0200 != null) {
                                        throw new IllegalArgumentException("Conflicting fields:\n    " + c0200.f1665 + "\n    " + field);
                                    }
                                }
                                i3++;
                                cls8 = cls;
                                zM9582 = z;
                                z3 = z2;
                                linkedHashSet2 = linkedHashSet;
                                declaredFields = fieldArr;
                            }
                            Class cls10 = ᵥˈᵛ.ˁˌᵩ(typeM9584);
                            typeM9584 = AbstractC4534.m9584(typeM9584, cls10, cls10.getGenericSuperclass(), new LinkedHashSet());
                            i = 0;
                        }
                        return new C5547(c2868, treeMap).m8143();
                    }
                    abstractC3610 = null;
                }
                return abstractC3610;
            case 2:
                Class cls11 = ᵥˈᵛ.ˁˌᵩ(typeM9584);
                if (!set.isEmpty()) {
                    return null;
                }
                if (cls11 == List.class || cls11 == Collection.class) {
                    return new C2838(c5185.m10734(ᵥˈᵛ.ᵱʡˏ(typeM9584, Collection.class), AbstractC4534.f17254, null), 0).m8143();
                }
                if (cls11 == Set.class) {
                    return new C2838(c5185.m10734(ᵥˈᵛ.ᵱʡˏ(typeM9584, Collection.class), AbstractC4534.f17254, null), 1).m8143();
                }
                return null;
            case 3:
                if (!set.isEmpty() || (cls2 = ᵥˈᵛ.ˁˌᵩ(typeM9584)) != Map.class) {
                    return null;
                }
                if (typeM9584 == Properties.class) {
                    actualTypeArguments = new Type[]{String.class, String.class};
                } else {
                    if (!Map.class.isAssignableFrom(cls2)) {
                        ᵷᵝˎ.ᵷᵺʾᵖ();
                        return null;
                    }
                    Type typeM95843 = AbstractC4534.m9584(typeM9584, cls2, AbstractC4534.m9577(typeM9584, cls2, Map.class), new LinkedHashSet());
                    if (!(typeM95843 instanceof ParameterizedType)) {
                        c = 0;
                        actualTypeArguments = new Type[]{Object.class, Object.class};
                        return new ˊʧʘ(c5185, actualTypeArguments[c], actualTypeArguments[1]).m8143();
                    }
                    actualTypeArguments = ((ParameterizedType) typeM95843).getActualTypeArguments();
                }
                c = 0;
                return new ˊʧʘ(c5185, actualTypeArguments[c], actualTypeArguments[1]).m8143();
            case 4:
                return null;
            default:
                ᵧˌ r0 = ᵝˉː.ᵱᵽʡᵚ;
                ᵧˌ r3 = ᵝˉː.ᵻʽᵯ;
                ᵧˌ r4 = ᵝˉː.ˊᵫᵗ;
                ᵧˌ r5 = ᵝˉː.ᵵᵽ;
                ᵧˌ r6 = ᵝˉː.ᵻˈᵦʼ;
                ᵧˌ r14 = ᵝˉː.ᵨᵣ;
                ᵧˌ r15 = ᵝˉː.ᵷᵺʾᵖ;
                ᵧˌ r16 = ᵝˉː.ːˏᵟᵯ;
                if (!set.isEmpty()) {
                    return null;
                }
                if (typeM9584 == Boolean.TYPE) {
                    return r16;
                }
                if (typeM9584 == Byte.TYPE) {
                    return r15;
                }
                if (typeM9584 == Character.TYPE) {
                    return r14;
                }
                if (typeM9584 == Double.TYPE) {
                    return r6;
                }
                if (typeM9584 == Float.TYPE) {
                    return r5;
                }
                if (typeM9584 == cls4) {
                    return r4;
                }
                if (typeM9584 == Long.TYPE) {
                    return r3;
                }
                if (typeM9584 == Short.TYPE) {
                    return r0;
                }
                if (typeM9584 == Boolean.class) {
                    return r16.m8143();
                }
                if (typeM9584 == Byte.class) {
                    return r15.m8143();
                }
                if (typeM9584 == Character.class) {
                    return r14.m8143();
                }
                if (typeM9584 == Double.class) {
                    return r6.m8143();
                }
                if (typeM9584 == Float.class) {
                    return r5.m8143();
                }
                if (typeM9584 == Integer.class) {
                    return r4.m8143();
                }
                if (typeM9584 == Long.class) {
                    return r3.m8143();
                }
                if (typeM9584 == Short.class) {
                    return r0.m8143();
                }
                if (typeM9584 == String.class) {
                    return ᵝˉː.ᵶᵥᵝ.m8143();
                }
                if (typeM9584 == Object.class) {
                    return new C2672(c5185).m8143();
                }
                Class cls12 = ᵥˈᵛ.ˁˌᵩ(typeM9584);
                Set set2 = AbstractC4534.f17254;
                InterfaceC0874 interfaceC0874 = (InterfaceC0874) cls12.getAnnotation(InterfaceC0874.class);
                if (interfaceC0874 != null && interfaceC0874.generateAdapter()) {
                    try {
                        try {
                            cls3 = Class.forName(cls12.getName().replace("$", "_") + "JsonAdapter", true, cls12.getClassLoader());
                        } catch (NoSuchMethodException e2) {
                            e = e2;
                            cls3 = null;
                        }
                        try {
                            if (typeM9584 instanceof ParameterizedType) {
                                Type[] actualTypeArguments2 = ((ParameterizedType) typeM9584).getActualTypeArguments();
                                try {
                                    declaredConstructor = cls3.getDeclaredConstructor(C5185.class, Type[].class);
                                    objArr = new Object[]{c5185, actualTypeArguments2};
                                } catch (NoSuchMethodException unused7) {
                                    declaredConstructor = cls3.getDeclaredConstructor(Type[].class);
                                    objArr = new Object[]{actualTypeArguments2};
                                }
                            } else {
                                try {
                                    declaredConstructor = cls3.getDeclaredConstructor(C5185.class);
                                    objArr = new Object[]{c5185};
                                } catch (NoSuchMethodException unused8) {
                                    declaredConstructor = cls3.getDeclaredConstructor(null);
                                    objArr = new Object[0];
                                }
                            }
                            declaredConstructor.setAccessible(true);
                            c2807M8143 = ((AbstractC3610) declaredConstructor.newInstance(objArr)).m8143();
                        } catch (NoSuchMethodException e3) {
                            e = e3;
                            if ((typeM9584 instanceof ParameterizedType) || cls3.getTypeParameters().length == 0) {
                                ᵷᵝˎ.ˋˈ("Failed to find the generated JsonAdapter constructor for ", typeM9584, e);
                                return null;
                            }
                            StringBuilder sb = new StringBuilder("Failed to find the generated JsonAdapter constructor for '");
                            sb.append(typeM9584);
                            String canonicalName = cls3.getCanonicalName();
                            sb.append("'. Suspiciously, the type was not parameterized but the target class '");
                            sb.append(canonicalName);
                            sb.append("' is generic. Consider using Types#newParameterizedType() to define these missing type variables.");
                            throw new RuntimeException(sb.toString(), e);
                        }
                    } catch (ClassNotFoundException e4) {
                        ᵷᵝˎ.ˋˈ("Failed to find the generated JsonAdapter class for ", typeM9584, e4);
                        return null;
                    } catch (IllegalAccessException e5) {
                        ᵷᵝˎ.ˋˈ("Failed to access the generated JsonAdapter for ", typeM9584, e5);
                        return null;
                    } catch (InstantiationException e6) {
                        ᵷᵝˎ.ˋˈ("Failed to instantiate the generated JsonAdapter for ", typeM9584, e6);
                        return null;
                    } catch (InvocationTargetException e7) {
                        AbstractC4534.m9581(e7);
                        throw null;
                    }
                    break;
                } else {
                    c2807M8143 = null;
                }
                if (c2807M8143 != null) {
                    return c2807M8143;
                }
                if (cls12.isEnum()) {
                    return new C4846(cls12).m8143();
                }
                return null;
        }
    }
}
