package com.facebook.internal; import com.facebook.FacebookRequestError; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import kotlin.TuplesKt; import kotlin.collections.MapsKt__MapsKt; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.text.StringsKt__StringsJVMKt; import org.json.JSONArray; import org.json.JSONObject; /* loaded from: classes2.dex */ public final class FacebookRequestErrorClassification { public static final Companion Companion = new Companion(null); public static final int EC_APP_NOT_INSTALLED = 412; public static final int EC_APP_TOO_MANY_CALLS = 4; public static final int EC_INVALID_SESSION = 102; public static final int EC_INVALID_TOKEN = 190; public static final int EC_RATE = 9; public static final int EC_SERVICE_UNAVAILABLE = 2; public static final int EC_TOO_MANY_USER_ACTION_CALLS = 341; public static final int EC_USER_TOO_MANY_CALLS = 17; public static final int ESC_APP_INACTIVE = 493; public static final int ESC_APP_NOT_INSTALLED = 458; public static final String KEY_LOGIN_RECOVERABLE = "login_recoverable"; public static final String KEY_NAME = "name"; public static final String KEY_OTHER = "other"; public static final String KEY_RECOVERY_MESSAGE = "recovery_message"; public static final String KEY_TRANSIENT = "transient"; private static FacebookRequestErrorClassification defaultInstance; private final Map> loginRecoverableErrors; private final String loginRecoverableRecoveryMessage; private final Map> otherErrors; private final String otherRecoveryMessage; private final Map> transientErrors; private final String transientRecoveryMessage; public /* synthetic */ class WhenMappings { public static final /* synthetic */ int[] $EnumSwitchMapping$0; static { int[] iArr = new int[FacebookRequestError.Category.valuesCustom().length]; iArr[FacebookRequestError.Category.OTHER.ordinal()] = 1; iArr[FacebookRequestError.Category.LOGIN_RECOVERABLE.ordinal()] = 2; iArr[FacebookRequestError.Category.TRANSIENT.ordinal()] = 3; $EnumSwitchMapping$0 = iArr; } } public static final FacebookRequestErrorClassification createFromJSON(JSONArray jSONArray) { return Companion.createFromJSON(jSONArray); } public static final synchronized FacebookRequestErrorClassification getDefaultErrorClassification() { FacebookRequestErrorClassification defaultErrorClassification; synchronized (FacebookRequestErrorClassification.class) { defaultErrorClassification = Companion.getDefaultErrorClassification(); } return defaultErrorClassification; } public final Map> getLoginRecoverableErrors() { return this.loginRecoverableErrors; } public final Map> getOtherErrors() { return this.otherErrors; } public final Map> getTransientErrors() { return this.transientErrors; } /* JADX WARN: Multi-variable type inference failed */ public FacebookRequestErrorClassification(Map> map, Map> map2, Map> map3, String str, String str2, String str3) { this.otherErrors = map; this.transientErrors = map2; this.loginRecoverableErrors = map3; this.otherRecoveryMessage = str; this.transientRecoveryMessage = str2; this.loginRecoverableRecoveryMessage = str3; } public final String getRecoveryMessage(FacebookRequestError.Category category) { int i = category == null ? -1 : WhenMappings.$EnumSwitchMapping$0[category.ordinal()]; if (i == 1) { return this.otherRecoveryMessage; } if (i == 2) { return this.loginRecoverableRecoveryMessage; } if (i != 3) { return null; } return this.transientRecoveryMessage; } public final FacebookRequestError.Category classify(int i, int i2, boolean z) { Set set; Set set2; Set set3; if (z) { return FacebookRequestError.Category.TRANSIENT; } Map> map = this.otherErrors; if (map != null && map.containsKey(Integer.valueOf(i)) && ((set3 = this.otherErrors.get(Integer.valueOf(i))) == null || set3.contains(Integer.valueOf(i2)))) { return FacebookRequestError.Category.OTHER; } Map> map2 = this.loginRecoverableErrors; if (map2 != null && map2.containsKey(Integer.valueOf(i)) && ((set2 = this.loginRecoverableErrors.get(Integer.valueOf(i))) == null || set2.contains(Integer.valueOf(i2)))) { return FacebookRequestError.Category.LOGIN_RECOVERABLE; } Map> map3 = this.transientErrors; if (map3 != null && map3.containsKey(Integer.valueOf(i)) && ((set = this.transientErrors.get(Integer.valueOf(i))) == null || set.contains(Integer.valueOf(i2)))) { return FacebookRequestError.Category.TRANSIENT; } return FacebookRequestError.Category.OTHER; } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public static /* synthetic */ void getDefaultErrorClassification$annotations() { } private Companion() { } public final synchronized FacebookRequestErrorClassification getDefaultErrorClassification() { FacebookRequestErrorClassification facebookRequestErrorClassification; try { if (FacebookRequestErrorClassification.defaultInstance == null) { FacebookRequestErrorClassification.defaultInstance = getDefaultErrorClassificationImpl(); } facebookRequestErrorClassification = FacebookRequestErrorClassification.defaultInstance; if (facebookRequestErrorClassification == null) { throw new NullPointerException("null cannot be cast to non-null type com.facebook.internal.FacebookRequestErrorClassification"); } } catch (Throwable th) { throw th; } return facebookRequestErrorClassification; } private final FacebookRequestErrorClassification getDefaultErrorClassificationImpl() { HashMap hashMapOf; HashMap hashMapOf2; hashMapOf = MapsKt__MapsKt.hashMapOf(TuplesKt.to(2, null), TuplesKt.to(4, null), TuplesKt.to(9, null), TuplesKt.to(17, null), TuplesKt.to(Integer.valueOf(FacebookRequestErrorClassification.EC_TOO_MANY_USER_ACTION_CALLS), null)); hashMapOf2 = MapsKt__MapsKt.hashMapOf(TuplesKt.to(102, null), TuplesKt.to(Integer.valueOf(FacebookRequestErrorClassification.EC_INVALID_TOKEN), null), TuplesKt.to(412, null)); return new FacebookRequestErrorClassification(null, hashMapOf, hashMapOf2, null, null, null); } private final Map> parseJSONDefinition(JSONObject jSONObject) { int optInt; HashSet hashSet; JSONArray optJSONArray = jSONObject.optJSONArray("items"); if (optJSONArray == null || optJSONArray.length() == 0) { return null; } HashMap hashMap = new HashMap(); int length = optJSONArray.length(); if (length > 0) { int i = 0; while (true) { int i2 = i + 1; JSONObject optJSONObject = optJSONArray.optJSONObject(i); if (optJSONObject != null && (optInt = optJSONObject.optInt("code")) != 0) { JSONArray optJSONArray2 = optJSONObject.optJSONArray("subcodes"); if (optJSONArray2 == null || optJSONArray2.length() <= 0) { hashSet = null; } else { hashSet = new HashSet(); int length2 = optJSONArray2.length(); if (length2 > 0) { int i3 = 0; while (true) { int i4 = i3 + 1; int optInt2 = optJSONArray2.optInt(i3); if (optInt2 != 0) { hashSet.add(Integer.valueOf(optInt2)); } if (i4 >= length2) { break; } i3 = i4; } } } hashMap.put(Integer.valueOf(optInt), hashSet); } if (i2 >= length) { break; } i = i2; } } return hashMap; } public final FacebookRequestErrorClassification createFromJSON(JSONArray jSONArray) { Map> map; Map> map2; Map> map3; String str; String str2; String str3; String optString; boolean equals; boolean equals2; boolean equals3; if (jSONArray == null) { return null; } int length = jSONArray.length(); if (length > 0) { int i = 0; Map> map4 = null; Map> map5 = null; Map> map6 = null; String str4 = null; String str5 = null; String str6 = null; while (true) { int i2 = i + 1; JSONObject optJSONObject = jSONArray.optJSONObject(i); if (optJSONObject != null && (optString = optJSONObject.optString("name")) != null) { equals = StringsKt__StringsJVMKt.equals(optString, "other", true); if (equals) { str4 = optJSONObject.optString(FacebookRequestErrorClassification.KEY_RECOVERY_MESSAGE, null); map4 = parseJSONDefinition(optJSONObject); } else { equals2 = StringsKt__StringsJVMKt.equals(optString, FacebookRequestErrorClassification.KEY_TRANSIENT, true); if (equals2) { str5 = optJSONObject.optString(FacebookRequestErrorClassification.KEY_RECOVERY_MESSAGE, null); map5 = parseJSONDefinition(optJSONObject); } else { equals3 = StringsKt__StringsJVMKt.equals(optString, FacebookRequestErrorClassification.KEY_LOGIN_RECOVERABLE, true); if (equals3) { str6 = optJSONObject.optString(FacebookRequestErrorClassification.KEY_RECOVERY_MESSAGE, null); map6 = parseJSONDefinition(optJSONObject); } } } } if (i2 >= length) { break; } i = i2; } map = map4; map2 = map5; map3 = map6; str = str4; str2 = str5; str3 = str6; } else { map = null; map2 = null; map3 = null; str = null; str2 = null; str3 = null; } return new FacebookRequestErrorClassification(map, map2, map3, str, str2, str3); } } }