package com.google.protobuf;

import com.revenuecat.purchases.subscriberattributes.SubscriberAttributeKt;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/* JADX INFO: renamed from: com.google.protobuf.v0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC1336v0 {

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

    static {
        char[] cArr = new char[80];
        f14364a = cArr;
        Arrays.fill(cArr, ' ');
    }

    public static void a(int i6, StringBuilder sb) {
        while (i6 > 0) {
            int i7 = 80;
            if (i6 <= 80) {
                i7 = i6;
            }
            sb.append(f14364a, 0, i7);
            i6 -= i7;
        }
    }

    public static void b(StringBuilder sb, int i6, String str, Object obj) {
        if (obj instanceof List) {
            Iterator it = ((List) obj).iterator();
            while (it.hasNext()) {
                b(sb, i6, str, it.next());
            }
            return;
        }
        if (obj instanceof Map) {
            Iterator it2 = ((Map) obj).entrySet().iterator();
            while (it2.hasNext()) {
                b(sb, i6, str, (Map.Entry) it2.next());
            }
            return;
        }
        sb.append('\n');
        a(i6, sb);
        if (!str.isEmpty()) {
            StringBuilder sb2 = new StringBuilder();
            sb2.append(Character.toLowerCase(str.charAt(0)));
            for (int i7 = 1; i7 < str.length(); i7++) {
                char cCharAt = str.charAt(i7);
                if (Character.isUpperCase(cCharAt)) {
                    sb2.append("_");
                }
                sb2.append(Character.toLowerCase(cCharAt));
            }
            str = sb2.toString();
        }
        sb.append(str);
        if (obj instanceof String) {
            sb.append(": \"");
            sb.append(O0.r(AbstractC1320n.m((String) obj)));
            sb.append('\"');
            return;
        }
        if (obj instanceof AbstractC1320n) {
            sb.append(": \"");
            sb.append(O0.r((AbstractC1320n) obj));
            sb.append('\"');
            return;
        }
        if (obj instanceof L) {
            sb.append(" {");
            c((L) obj, sb, i6 + 2);
            sb.append("\n");
            a(i6, sb);
            sb.append("}");
            return;
        }
        if (!(obj instanceof Map.Entry)) {
            sb.append(": ");
            sb.append(obj);
            return;
        }
        sb.append(" {");
        Map.Entry entry = (Map.Entry) obj;
        int i8 = i6 + 2;
        b(sb, i8, SubscriberAttributeKt.JSON_NAME_KEY, entry.getKey());
        b(sb, i8, "value", entry.getValue());
        sb.append("\n");
        a(i6, sb);
        sb.append("}");
    }

    /* JADX WARN: Removed duplicated region for block: B:64:0x0166  */
    /* JADX WARN: Removed duplicated region for block: B:75:0x019c  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x019e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void c(L l, StringBuilder sb, int i6) {
        int i7;
        int i8;
        boolean zBooleanValue;
        boolean zEquals;
        Method method;
        Method method2;
        HashSet hashSet = new HashSet();
        HashMap map = new HashMap();
        TreeMap treeMap = new TreeMap();
        Method[] declaredMethods = l.getClass().getDeclaredMethods();
        int length = declaredMethods.length;
        int i9 = 0;
        while (true) {
            i7 = 3;
            if (i9 >= length) {
                break;
            }
            Method method3 = declaredMethods[i9];
            if (!Modifier.isStatic(method3.getModifiers()) && method3.getName().length() >= 3) {
                if (method3.getName().startsWith("set")) {
                    hashSet.add(method3.getName());
                } else if (Modifier.isPublic(method3.getModifiers()) && method3.getParameterTypes().length == 0) {
                    if (method3.getName().startsWith("has")) {
                        map.put(method3.getName(), method3);
                    } else if (method3.getName().startsWith("get")) {
                        treeMap.put(method3.getName(), method3);
                    }
                }
            }
            i9++;
        }
        for (Map.Entry entry : treeMap.entrySet()) {
            String strSubstring = ((String) entry.getKey()).substring(i7);
            if (!strSubstring.endsWith("List") || strSubstring.endsWith("OrBuilderList") || strSubstring.equals("List") || (method2 = (Method) entry.getValue()) == null) {
                i8 = i7;
            } else {
                i8 = i7;
                if (method2.getReturnType().equals(List.class)) {
                    b(sb, i6, strSubstring.substring(0, strSubstring.length() - 4), L.invokeOrDie(method2, l, new Object[0]));
                }
                i7 = i8;
            }
            if (strSubstring.endsWith("Map") && !strSubstring.equals("Map") && (method = (Method) entry.getValue()) != null && method.getReturnType().equals(Map.class) && !method.isAnnotationPresent(Deprecated.class) && Modifier.isPublic(method.getModifiers())) {
                b(sb, i6, strSubstring.substring(0, strSubstring.length() - 3), L.invokeOrDie(method, l, new Object[0]));
            } else if (hashSet.contains("set".concat(strSubstring))) {
                if (strSubstring.endsWith("Bytes")) {
                    if (!treeMap.containsKey("get" + strSubstring.substring(0, strSubstring.length() - 5))) {
                        Method method4 = (Method) entry.getValue();
                        Method method5 = (Method) map.get("has".concat(strSubstring));
                        if (method4 != null) {
                            Object objInvokeOrDie = L.invokeOrDie(method4, l, new Object[0]);
                            if (method5 == null) {
                                zBooleanValue = true;
                                if (objInvokeOrDie instanceof Boolean) {
                                    zEquals = !((Boolean) objInvokeOrDie).booleanValue();
                                } else if (objInvokeOrDie instanceof Integer) {
                                    zEquals = ((Integer) objInvokeOrDie).intValue() == 0;
                                } else if (objInvokeOrDie instanceof Float) {
                                    if (Float.floatToRawIntBits(((Float) objInvokeOrDie).floatValue()) == 0) {
                                    }
                                } else if (objInvokeOrDie instanceof Double) {
                                    if (Double.doubleToRawLongBits(((Double) objInvokeOrDie).doubleValue()) == 0) {
                                    }
                                } else if (objInvokeOrDie instanceof String) {
                                    zEquals = objInvokeOrDie.equals("");
                                } else if (objInvokeOrDie instanceof AbstractC1320n) {
                                    zEquals = objInvokeOrDie.equals(AbstractC1320n.f14310b);
                                } else if (!(objInvokeOrDie instanceof InterfaceC1332t0) ? !(objInvokeOrDie instanceof Enum) || ((Enum) objInvokeOrDie).ordinal() != 0 : objInvokeOrDie != ((InterfaceC1332t0) objInvokeOrDie).getDefaultInstanceForType()) {
                                }
                                if (zEquals) {
                                    zBooleanValue = false;
                                }
                            } else {
                                zBooleanValue = ((Boolean) L.invokeOrDie(method5, l, new Object[0])).booleanValue();
                            }
                            if (zBooleanValue) {
                                b(sb, i6, strSubstring, objInvokeOrDie);
                            }
                        }
                    }
                }
            }
            i7 = i8;
        }
        T0 t02 = l.unknownFields;
        if (t02 != null) {
            for (int i10 = 0; i10 < t02.f14226a; i10++) {
                b(sb, i6, String.valueOf(t02.f14227b[i10] >>> 3), t02.f14228c[i10]);
            }
        }
    }
}
