package l;

import e.InterfaceC0451b;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
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.Map;
import okhttp3.HttpUrl;

/* JADX INFO: renamed from: l.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0611c implements Comparable {

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    public final Type f5243H;

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

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public final boolean f5245L;

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

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

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

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    private final InterfaceC0451b f5249a0;

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

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    private final InterfaceC0451b f5251b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public final boolean f5252c0;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public final boolean f5253d0;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public final char[] f5254e0;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public final boolean f5255f0;

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

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public final boolean f5257g0;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public final boolean f5258h0;

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

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public final String[] f5260j0;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public final long f5261k0;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final Field f5262r;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private int f5263x;

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

    public C0611c(String str, Class cls, Class cls2, Type type, Field field, int i2, int i3, int i4) {
        this.f5263x = 0;
        i2 = i2 < 0 ? 0 : i2;
        this.f5250b = str;
        this.f5244I = cls;
        this.f5264y = cls2;
        this.f5243H = type;
        this.f5256g = null;
        this.f5262r = field;
        this.f5263x = i2;
        this.f5246M = i3;
        this.f5247Q = i4;
        this.f5255f0 = cls2.isEnum();
        if (field != null) {
            int modifiers = field.getModifiers();
            this.f5252c0 = true;
            this.f5253d0 = Modifier.isTransient(modifiers);
        } else {
            this.f5253d0 = false;
            this.f5252c0 = false;
        }
        this.f5254e0 = b();
        if (field != null) {
            l.K0(field);
        }
        this.f5248Z = HttpUrl.FRAGMENT_ENCODE_SET;
        InterfaceC0451b interfaceC0451b = field == null ? null : (InterfaceC0451b) l.N(field, InterfaceC0451b.class);
        this.f5249a0 = interfaceC0451b;
        this.f5251b0 = null;
        this.f5245L = false;
        this.f5257g0 = false;
        this.f5258h0 = false;
        this.f5259i0 = null;
        this.f5260j0 = new String[0];
        this.f5261k0 = m(str, interfaceC0451b);
    }

    private static boolean e(Type[] typeArr, Map map) {
        if (map == null || map.size() == 0) {
            return false;
        }
        boolean z2 = false;
        for (int i2 = 0; i2 < typeArr.length; i2++) {
            Type type = typeArr[i2];
            if (type instanceof ParameterizedType) {
                ParameterizedType parameterizedType = (ParameterizedType) type;
                Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
                if (e(actualTypeArguments, map)) {
                    typeArr[i2] = new C0616h(actualTypeArguments, parameterizedType.getOwnerType(), parameterizedType.getRawType());
                    z2 = true;
                }
            } else if ((type instanceof TypeVariable) && map.containsKey(type)) {
                typeArr[i2] = (Type) map.get(type);
                z2 = true;
            }
        }
        return z2;
    }

    private static boolean f(Type[] typeArr, TypeVariable[] typeVariableArr, Type[] typeArr2) {
        if (typeArr2 == null || typeVariableArr.length == 0) {
            return false;
        }
        boolean z2 = false;
        for (int i2 = 0; i2 < typeArr.length; i2++) {
            Type type = typeArr[i2];
            if (type instanceof ParameterizedType) {
                ParameterizedType parameterizedType = (ParameterizedType) type;
                Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
                if (f(actualTypeArguments, typeVariableArr, typeArr2)) {
                    typeArr[i2] = new C0616h(actualTypeArguments, parameterizedType.getOwnerType(), parameterizedType.getRawType());
                    z2 = true;
                }
            } else if (type instanceof TypeVariable) {
                for (int i3 = 0; i3 < typeVariableArr.length; i3++) {
                    if (type.equals(typeVariableArr[i3])) {
                        typeArr[i2] = typeArr2[i3];
                        z2 = true;
                    }
                }
            }
        }
        return z2;
    }

    public static Type h(Class cls, Type type, Type type2) {
        return i(cls, type, type2, null);
    }

    public static Type i(Class cls, Type type, Type type2, Map map) {
        TypeVariable<Class<?>>[] typeParameters;
        ParameterizedType parameterizedType;
        if (cls != null && type != null) {
            if (type2 instanceof GenericArrayType) {
                Type genericComponentType = ((GenericArrayType) type2).getGenericComponentType();
                Type typeI = i(cls, type, genericComponentType, map);
                return genericComponentType != typeI ? Array.newInstance((Class<?>) l.P(typeI), 0).getClass() : type2;
            }
            if (!l.o0(type)) {
                return type2;
            }
            if (type2 instanceof TypeVariable) {
                ParameterizedType parameterizedType2 = (ParameterizedType) l.Y(type);
                TypeVariable typeVariable = (TypeVariable) type2;
                TypeVariable[] typeParameters2 = l.P(parameterizedType2).getTypeParameters();
                for (int i2 = 0; i2 < typeParameters2.length; i2++) {
                    if (typeParameters2[i2].getName().equals(typeVariable.getName())) {
                        return parameterizedType2.getActualTypeArguments()[i2];
                    }
                }
            }
            if (type2 instanceof ParameterizedType) {
                ParameterizedType parameterizedType3 = (ParameterizedType) type2;
                Type[] actualTypeArguments = parameterizedType3.getActualTypeArguments();
                boolean zE = e(actualTypeArguments, map);
                if (!zE) {
                    if (type instanceof ParameterizedType) {
                        parameterizedType = (ParameterizedType) type;
                        typeParameters = cls.getTypeParameters();
                    } else if (cls.getGenericSuperclass() instanceof ParameterizedType) {
                        parameterizedType = (ParameterizedType) cls.getGenericSuperclass();
                        typeParameters = cls.getSuperclass().getTypeParameters();
                    } else {
                        typeParameters = type.getClass().getTypeParameters();
                        parameterizedType = parameterizedType3;
                    }
                    zE = f(actualTypeArguments, typeParameters, parameterizedType.getActualTypeArguments());
                }
                if (zE) {
                    return new C0616h(actualTypeArguments, parameterizedType3.getOwnerType(), parameterizedType3.getRawType());
                }
            }
        }
        return type2;
    }

    private static Type k(Class cls, Type type, TypeVariable typeVariable) {
        Type[] actualTypeArguments;
        Class cls2 = typeVariable.getGenericDeclaration() instanceof Class ? (Class) typeVariable.getGenericDeclaration() : null;
        if (cls2 == cls) {
            actualTypeArguments = type instanceof ParameterizedType ? ((ParameterizedType) type).getActualTypeArguments() : null;
        } else {
            Type[] typeArr = null;
            while (cls != null && cls != Object.class && cls != cls2) {
                Type genericSuperclass = cls.getGenericSuperclass();
                if (genericSuperclass instanceof ParameterizedType) {
                    Type[] actualTypeArguments2 = ((ParameterizedType) genericSuperclass).getActualTypeArguments();
                    f(actualTypeArguments2, cls.getTypeParameters(), typeArr);
                    typeArr = actualTypeArguments2;
                }
                cls = cls.getSuperclass();
            }
            actualTypeArguments = typeArr;
        }
        if (actualTypeArguments == null || cls2 == null) {
            return null;
        }
        TypeVariable[] typeParameters = cls2.getTypeParameters();
        for (int i2 = 0; i2 < typeParameters.length; i2++) {
            if (typeVariable.equals(typeParameters[i2])) {
                return actualTypeArguments[i2];
            }
        }
        return null;
    }

    private long m(String str, InterfaceC0451b interfaceC0451b) {
        return (interfaceC0451b == null || interfaceC0451b.name().length() == 0) ? l.K(str) : l.J(str);
    }

    @Override // java.lang.Comparable
    /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
    public int compareTo(C0611c c0611c) {
        int i2 = this.f5263x;
        int i3 = c0611c.f5263x;
        if (i2 < i3) {
            return -1;
        }
        if (i2 > i3) {
            return 1;
        }
        int iCompareTo = this.f5250b.compareTo(c0611c.f5250b);
        if (iCompareTo != 0) {
            return iCompareTo;
        }
        Class<?> clsG = g();
        Class<?> clsG2 = c0611c.g();
        if (clsG != null && clsG2 != null && clsG != clsG2) {
            if (clsG.isAssignableFrom(clsG2)) {
                return -1;
            }
            if (clsG2.isAssignableFrom(clsG)) {
                return 1;
            }
        }
        Field field = this.f5262r;
        boolean z2 = false;
        boolean z3 = field != null && field.getType() == this.f5264y;
        Field field2 = c0611c.f5262r;
        if (field2 != null && field2.getType() == c0611c.f5264y) {
            z2 = true;
        }
        if (z3 && !z2) {
            return 1;
        }
        if (z2 && !z3) {
            return -1;
        }
        if (c0611c.f5264y.isPrimitive() && !this.f5264y.isPrimitive()) {
            return 1;
        }
        if (this.f5264y.isPrimitive() && !c0611c.f5264y.isPrimitive()) {
            return -1;
        }
        if (c0611c.f5264y.getName().startsWith("java.") && !this.f5264y.getName().startsWith("java.")) {
            return 1;
        }
        if (!this.f5264y.getName().startsWith("java.") || c0611c.f5264y.getName().startsWith("java.")) {
            return this.f5264y.getName().compareTo(c0611c.f5264y.getName());
        }
        return -1;
    }

    protected char[] b() {
        int length = this.f5250b.length();
        char[] cArr = new char[length + 3];
        String str = this.f5250b;
        str.getChars(0, str.length(), cArr, 1);
        cArr[0] = '\"';
        cArr[length + 1] = '\"';
        cArr[length + 2] = ':';
        return cArr;
    }

    public Object c(Object obj) {
        Method method = this.f5256g;
        return method != null ? method.invoke(obj, null) : this.f5262r.get(obj);
    }

    public InterfaceC0451b d() {
        InterfaceC0451b interfaceC0451b = this.f5249a0;
        return interfaceC0451b != null ? interfaceC0451b : this.f5251b0;
    }

    protected Class g() {
        Method method = this.f5256g;
        if (method != null) {
            return method.getDeclaringClass();
        }
        Field field = this.f5262r;
        if (field != null) {
            return field.getDeclaringClass();
        }
        return null;
    }

    public String j() {
        return this.f5259i0;
    }

    public Member l() {
        Method method = this.f5256g;
        return method != null ? method : this.f5262r;
    }

    public void n(Object obj, Object obj2) throws IllegalAccessException, InvocationTargetException {
        Method method = this.f5256g;
        if (method != null) {
            method.invoke(obj, obj2);
        } else {
            this.f5262r.set(obj, obj2);
        }
    }

    public void o() {
        Method method = this.f5256g;
        if (method != null) {
            l.K0(method);
        } else {
            l.K0(this.f5262r);
        }
    }

    public String toString() {
        return this.f5250b;
    }

    public C0611c(String str, Method method, Field field, Class cls, Type type, int i2, int i3, int i4, InterfaceC0451b interfaceC0451b, InterfaceC0451b interfaceC0451b2, String str2) {
        this(str, method, field, cls, type, i2, i3, i4, interfaceC0451b, interfaceC0451b2, str2, null);
    }

    public C0611c(String str, Method method, Field field, Class cls, Type type, int i2, int i3, int i4, InterfaceC0451b interfaceC0451b, InterfaceC0451b interfaceC0451b2, String str2, Map map) {
        boolean zJsonDirect;
        boolean zIsFinal;
        Class<?> cls2;
        Type type2;
        Type typeK;
        Class<?> cls3;
        Class<?> cls4;
        Type genericReturnType;
        Class<?> returnType;
        Type type3;
        boolean z2 = false;
        this.f5263x = 0;
        if (field != null) {
            String name = field.getName();
            if (name.equals(str)) {
                str = name;
            }
        }
        i2 = i2 < 0 ? 0 : i2;
        this.f5250b = str;
        this.f5256g = method;
        this.f5262r = field;
        this.f5263x = i2;
        this.f5246M = i3;
        this.f5247Q = i4;
        this.f5249a0 = interfaceC0451b;
        this.f5251b0 = interfaceC0451b2;
        if (field != null) {
            int modifiers = field.getModifiers();
            this.f5252c0 = (modifiers & 1) != 0 || method == null;
            this.f5253d0 = Modifier.isTransient(modifiers) || l.x0(method);
        } else {
            this.f5252c0 = false;
            this.f5253d0 = l.x0(method);
        }
        if (str2 != null && str2.length() > 0) {
            this.f5248Z = str2;
        } else {
            this.f5248Z = HttpUrl.FRAGMENT_ENCODE_SET;
        }
        InterfaceC0451b interfaceC0451bD = d();
        this.f5261k0 = m(str, interfaceC0451bD);
        if (interfaceC0451bD != null) {
            String str3 = interfaceC0451bD.format();
            str = str3.trim().length() != 0 ? str3 : null;
            zJsonDirect = interfaceC0451bD.jsonDirect();
            this.f5258h0 = interfaceC0451bD.unwrapped();
            this.f5260j0 = interfaceC0451bD.alternateNames();
        } else {
            this.f5258h0 = false;
            this.f5260j0 = new String[0];
            zJsonDirect = false;
        }
        this.f5259i0 = str;
        this.f5254e0 = b();
        if (method != null) {
            l.K0(method);
        }
        if (field != null) {
            l.K0(field);
        }
        if (method != null) {
            Class<?>[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length == 1) {
                cls4 = parameterTypes[0];
                type3 = method.getGenericParameterTypes()[0];
            } else if (parameterTypes.length == 2 && (cls3 = parameterTypes[0]) == String.class && parameterTypes[1] == Object.class) {
                cls4 = cls3;
                type3 = cls3;
            } else {
                zIsFinal = true;
                returnType = method.getReturnType();
                genericReturnType = method.getGenericReturnType();
                this.f5244I = method.getDeclaringClass();
                cls2 = returnType;
                type2 = genericReturnType;
            }
            zIsFinal = false;
            returnType = cls4;
            genericReturnType = type3;
            this.f5244I = method.getDeclaringClass();
            cls2 = returnType;
            type2 = genericReturnType;
        } else {
            Class<?> type4 = field.getType();
            Type genericType = field.getGenericType();
            this.f5244I = field.getDeclaringClass();
            zIsFinal = Modifier.isFinal(field.getModifiers());
            cls2 = type4;
            type2 = genericType;
        }
        this.f5245L = zIsFinal;
        if (zJsonDirect && cls2 == String.class) {
            z2 = true;
        }
        this.f5257g0 = z2;
        if (cls != null && cls2 == Object.class && (type2 instanceof TypeVariable) && (typeK = k(cls, type, (TypeVariable) type2)) != null) {
            this.f5264y = l.P(typeK);
            this.f5243H = typeK;
            this.f5255f0 = cls2.isEnum();
            return;
        }
        boolean z3 = type2 instanceof Class;
        Class<?> cls5 = cls2;
        Type type5 = type2;
        if (!z3) {
            Type typeI = i(cls, type == null ? cls : type, type2, map);
            Class<?> clsP = cls2;
            if (typeI != type2) {
                if (typeI instanceof ParameterizedType) {
                    clsP = l.P(typeI);
                } else {
                    clsP = cls2;
                    if (typeI instanceof Class) {
                        clsP = l.P(typeI);
                    }
                }
            }
            type5 = typeI;
            cls5 = clsP;
        }
        this.f5243H = type5;
        this.f5264y = cls5;
        this.f5255f0 = cls5.isEnum();
    }
}
