package com.google.crypto.tink.shaded.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: loaded from: classes3.dex */
public abstract class S {

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

    static {
        char[] cArr = new char[80];
        f13738a = 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(f13738a, 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(": \"");
            C1260h c1260h = AbstractC1261i.f13790b;
            sb.append(W0.e.n(new C1260h(((String) obj).getBytes(A.f13714a))));
            sb.append('\"');
            return;
        }
        if (obj instanceof AbstractC1261i) {
            sb.append(": \"");
            sb.append(W0.e.n((AbstractC1261i) obj));
            sb.append('\"');
            return;
        }
        if (obj instanceof AbstractC1274w) {
            sb.append(" {");
            c((AbstractC1274w) 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(AbstractC1274w abstractC1274w, 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 = abstractC1274w.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), AbstractC1274w.k(method2, abstractC1274w, 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), AbstractC1274w.k(method, abstractC1274w, 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 objK = AbstractC1274w.k(method4, abstractC1274w, new Object[0]);
                            if (method5 == null) {
                                zBooleanValue = true;
                                if (objK instanceof Boolean) {
                                    zEquals = !((Boolean) objK).booleanValue();
                                } else if (objK instanceof Integer) {
                                    zEquals = ((Integer) objK).intValue() == 0;
                                } else if (objK instanceof Float) {
                                    if (Float.floatToRawIntBits(((Float) objK).floatValue()) == 0) {
                                    }
                                } else if (objK instanceof Double) {
                                    if (Double.doubleToRawLongBits(((Double) objK).doubleValue()) == 0) {
                                    }
                                } else if (objK instanceof String) {
                                    zEquals = objK.equals("");
                                } else if (objK instanceof AbstractC1261i) {
                                    zEquals = objK.equals(AbstractC1261i.f13790b);
                                } else if (!(objK instanceof AbstractC1253a) ? !(objK instanceof Enum) || ((Enum) objK).ordinal() != 0 : objK != ((AbstractC1253a) objK).getDefaultInstanceForType()) {
                                }
                                if (zEquals) {
                                    zBooleanValue = false;
                                }
                            } else {
                                zBooleanValue = ((Boolean) AbstractC1274w.k(method5, abstractC1274w, new Object[0])).booleanValue();
                            }
                            if (zBooleanValue) {
                                b(sb, i6, strSubstring, objK);
                            }
                        }
                    }
                }
            }
            i7 = i8;
        }
        f0 f0Var = abstractC1274w.unknownFields;
        if (f0Var != null) {
            for (int i10 = 0; i10 < f0Var.f13781a; i10++) {
                b(sb, i6, String.valueOf(f0Var.f13782b[i10] >>> 3), f0Var.f13783c[i10]);
            }
        }
    }
}
