package l;

import d.C0424d;
import d.EnumC0439l;
import e.InterfaceC0450a;
import e.InterfaceC0451b;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/* JADX INFO: renamed from: l.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0615g {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Class f5289a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Class f5290b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Constructor f5291c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Constructor f5292d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Method f5293e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Method f5294f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f5295g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final C0611c[] f5296h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final C0611c[] f5297i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final int f5298j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final e.d f5299k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final String f5300l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final String f5301m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public String[] f5302n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public Type[] f5303o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public String[] f5304p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public boolean f5305q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public Constructor f5306r;

    public C0615g(Class cls, Class cls2, Constructor constructor, Constructor constructor2, Method method, Method method2, e.d dVar, List list) {
        InterfaceC0451b interfaceC0451b;
        this.f5289a = cls;
        this.f5290b = cls2;
        this.f5291c = constructor;
        this.f5292d = constructor2;
        this.f5293e = method;
        this.f5298j = l.e0(cls);
        this.f5294f = method2;
        this.f5299k = dVar;
        if (dVar != null) {
            String strTypeName = dVar.typeName();
            String strTypeKey = dVar.typeKey();
            this.f5301m = strTypeKey.length() <= 0 ? null : strTypeKey;
            if (strTypeName.length() != 0) {
                this.f5300l = strTypeName;
            } else {
                this.f5300l = cls.getName();
            }
            String[] strArrOrders = dVar.orders();
            this.f5302n = strArrOrders.length == 0 ? null : strArrOrders;
        } else {
            this.f5300l = cls.getName();
            this.f5301m = null;
            this.f5302n = null;
        }
        C0611c[] c0611cArr = new C0611c[list.size()];
        this.f5296h = c0611cArr;
        list.toArray(c0611cArr);
        C0611c[] c0611cArr2 = new C0611c[c0611cArr.length];
        int i2 = 0;
        if (this.f5302n != null) {
            LinkedHashMap linkedHashMap = new LinkedHashMap(list.size());
            for (C0611c c0611c : c0611cArr) {
                linkedHashMap.put(c0611c.f5250b, c0611c);
            }
            int i3 = 0;
            for (String str : this.f5302n) {
                C0611c c0611c2 = (C0611c) linkedHashMap.get(str);
                if (c0611c2 != null) {
                    c0611cArr2[i3] = c0611c2;
                    linkedHashMap.remove(str);
                    i3++;
                }
            }
            Iterator it = linkedHashMap.values().iterator();
            while (it.hasNext()) {
                c0611cArr2[i3] = (C0611c) it.next();
                i3++;
            }
        } else {
            System.arraycopy(c0611cArr, 0, c0611cArr2, 0, c0611cArr.length);
            Arrays.sort(c0611cArr2);
        }
        this.f5297i = Arrays.equals(this.f5296h, c0611cArr2) ? this.f5296h : c0611cArr2;
        if (constructor != null) {
            this.f5295g = constructor.getParameterTypes().length;
        } else if (method != null) {
            this.f5295g = method.getParameterTypes().length;
        } else {
            this.f5295g = 0;
        }
        if (constructor2 != null) {
            this.f5303o = constructor2.getParameterTypes();
            boolean zS0 = l.s0(cls);
            this.f5305q = zS0;
            if (!zS0) {
                if (this.f5303o.length == this.f5296h.length) {
                    while (true) {
                        Type[] typeArr = this.f5303o;
                        if (i2 >= typeArr.length) {
                            return;
                        }
                        if (typeArr[i2] != this.f5296h[i2].f5264y) {
                            break;
                        } else {
                            i2++;
                        }
                    }
                }
                this.f5304p = AbstractC0610b.f(constructor2);
                return;
            }
            this.f5304p = l.Z(cls);
            try {
                this.f5306r = cls.getConstructor(null);
            } catch (Throwable unused) {
            }
            Annotation[][] annotationArrC0 = l.c0(constructor2);
            for (int i4 = 0; i4 < this.f5304p.length && i4 < annotationArrC0.length; i4++) {
                Annotation[] annotationArr = annotationArrC0[i4];
                int length = annotationArr.length;
                int i5 = 0;
                while (true) {
                    if (i5 >= length) {
                        interfaceC0451b = null;
                        break;
                    }
                    Annotation annotation = annotationArr[i5];
                    if (annotation instanceof InterfaceC0451b) {
                        interfaceC0451b = (InterfaceC0451b) annotation;
                        break;
                    }
                    i5++;
                }
                if (interfaceC0451b != null) {
                    String strName = interfaceC0451b.name();
                    if (strName.length() > 0) {
                        this.f5304p[i4] = strName;
                    }
                }
            }
        }
    }

    static boolean a(List list, C0611c c0611c) {
        for (int size = list.size() - 1; size >= 0; size--) {
            C0611c c0611c2 = (C0611c) list.get(size);
            if (c0611c2.f5250b.equals(c0611c.f5250b) && (!c0611c2.f5245L || c0611c.f5245L)) {
                if (c0611c2.f5264y.isAssignableFrom(c0611c.f5264y)) {
                    list.set(size, c0611c);
                    return true;
                }
                if (c0611c2.compareTo(c0611c) >= 0) {
                    return false;
                }
                list.set(size, c0611c);
                return true;
            }
        }
        list.add(c0611c);
        return true;
    }

    public static C0615g b(Class cls, Type type, EnumC0439l enumC0439l) {
        return c(cls, type, enumC0439l, false, l.f5332b, false);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:172:0x0357  */
    /* JADX WARN: Removed duplicated region for block: B:173:0x035c  */
    /* JADX WARN: Removed duplicated region for block: B:292:0x0697  */
    /* JADX WARN: Removed duplicated region for block: B:352:0x0849  */
    /* JADX WARN: Removed duplicated region for block: B:359:0x086a  */
    /* JADX WARN: Removed duplicated region for block: B:362:0x0876  */
    /* JADX WARN: Removed duplicated region for block: B:364:0x087a  */
    /* JADX WARN: Removed duplicated region for block: B:397:0x0931  */
    /* JADX WARN: Removed duplicated region for block: B:398:0x094c  */
    /* JADX WARN: Removed duplicated region for block: B:481:0x0bcf  */
    /* JADX WARN: Type inference failed for: r10v12 */
    /* JADX WARN: Type inference failed for: r10v13, types: [e.b] */
    /* JADX WARN: Type inference failed for: r10v14 */
    /* JADX WARN: Type inference failed for: r10v15 */
    /* JADX WARN: Type inference failed for: r6v25, types: [java.util.ArrayList, java.util.List] */
    /* JADX WARN: Type inference failed for: r6v6 */
    /* JADX WARN: Type inference failed for: r6v7, types: [java.util.List] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static l.C0615g c(java.lang.Class r57, java.lang.reflect.Type r58, d.EnumC0439l r59, boolean r60, boolean r61, boolean r62) {
        /*
            Method dump skipped, instruction units count: 3203
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: l.C0615g.c(java.lang.Class, java.lang.reflect.Type, d.l, boolean, boolean, boolean):l.g");
    }

    private static Map d(Class cls) {
        Class superclass = cls.getSuperclass();
        HashMap map = null;
        if (superclass == null) {
            return null;
        }
        while (true) {
            Class cls2 = superclass;
            Class cls3 = cls;
            cls = cls2;
            if (cls == null || cls == Object.class) {
                break;
            }
            if (cls3.getGenericSuperclass() instanceof ParameterizedType) {
                Type[] actualTypeArguments = ((ParameterizedType) cls3.getGenericSuperclass()).getActualTypeArguments();
                TypeVariable[] typeParameters = cls.getTypeParameters();
                for (int i2 = 0; i2 < actualTypeArguments.length; i2++) {
                    if (map == null) {
                        map = new HashMap();
                    }
                    if (map.containsKey(actualTypeArguments[i2])) {
                        map.put(typeParameters[i2], (Type) map.get(actualTypeArguments[i2]));
                    } else {
                        map.put(typeParameters[i2], actualTypeArguments[i2]);
                    }
                }
            }
            superclass = cls.getSuperclass();
        }
        return map;
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x0051  */
    /* JADX WARN: Removed duplicated region for block: B:6:0x0019 A[EDGE_INSN: B:44:0x0019->B:6:0x0019 BREAK  A[LOOP:1: B:20:0x0055->B:45:?]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static void e(java.lang.Class r20, java.lang.reflect.Type r21, d.EnumC0439l r22, java.util.List r23, java.lang.reflect.Field[] r24) {
        /*
            Method dump skipped, instruction units count: 221
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: l.C0615g.e(java.lang.Class, java.lang.reflect.Type, d.l, java.util.List, java.lang.reflect.Field[]):void");
    }

    public static Class f(Class cls, e.d dVar) {
        Class clsBuilder;
        if (cls != null && cls.getName().equals("org.springframework.security.web.savedrequest.DefaultSavedRequest")) {
            return l.z0("org.springframework.security.web.savedrequest.DefaultSavedRequest$Builder");
        }
        if (dVar == null || (clsBuilder = dVar.builder()) == Void.class) {
            return null;
        }
        return clsBuilder;
    }

    public static Constructor g(Constructor[] constructorArr) {
        Constructor constructor = null;
        for (Constructor constructor2 : constructorArr) {
            if (((InterfaceC0450a) constructor2.getAnnotation(InterfaceC0450a.class)) != null) {
                if (constructor != null) {
                    throw new C0424d("multi-JSONCreator");
                }
                constructor = constructor2;
            }
        }
        if (constructor != null) {
            return constructor;
        }
        for (Constructor constructor3 : constructorArr) {
            Annotation[][] annotationArrC0 = l.c0(constructor3);
            if (annotationArrC0.length != 0) {
                int length = annotationArrC0.length;
                int i2 = 0;
                while (true) {
                    if (i2 < length) {
                        for (Annotation annotation : annotationArrC0[i2]) {
                            if (annotation instanceof InterfaceC0451b) {
                                break;
                            }
                        }
                    } else {
                        if (constructor != null) {
                            throw new C0424d("multi-JSONCreator");
                        }
                        constructor = constructor3;
                    }
                    i2++;
                }
            }
        }
        return constructor;
    }

    static Constructor h(Class cls, Constructor[] constructorArr) {
        Constructor constructor = null;
        if (Modifier.isAbstract(cls.getModifiers())) {
            return null;
        }
        int length = constructorArr.length;
        int i2 = 0;
        while (true) {
            if (i2 >= length) {
                break;
            }
            Constructor constructor2 = constructorArr[i2];
            if (constructor2.getParameterTypes().length == 0) {
                constructor = constructor2;
                break;
            }
            i2++;
        }
        if (constructor != null || !cls.isMemberClass() || Modifier.isStatic(cls.getModifiers())) {
            return constructor;
        }
        for (Constructor constructor3 : constructorArr) {
            Class<?>[] parameterTypes = constructor3.getParameterTypes();
            if (parameterTypes.length == 1 && parameterTypes[0].equals(cls.getDeclaringClass())) {
                return constructor3;
            }
        }
        return constructor;
    }

    private static Method i(Class cls, Method[] methodArr, boolean z2) {
        Method method = null;
        for (Method method2 : methodArr) {
            if (Modifier.isStatic(method2.getModifiers()) && cls.isAssignableFrom(method2.getReturnType()) && ((InterfaceC0450a) l.O(method2, InterfaceC0450a.class)) != null) {
                if (method != null) {
                    throw new C0424d("multi-JSONCreator");
                }
                method = method2;
            }
        }
        if (method != null || !z2) {
            return method;
        }
        for (Method method3 : methodArr) {
            if (l.r0(method3)) {
                return method3;
            }
        }
        return method;
    }

    private static C0611c j(List list, String str) {
        Iterator it = list.iterator();
        while (it.hasNext()) {
            C0611c c0611c = (C0611c) it.next();
            if (c0611c.f5250b.equals(str)) {
                return c0611c;
            }
            Field field = c0611c.f5262r;
            if (field != null && c0611c.d() != null && field.getName().equals(str)) {
                return c0611c;
            }
        }
        return null;
    }
}
