package com.miraclegarden.smsmessage.xposed.hook;

/**
 * PH vs SG MariBank 差异配置（基于 reverse/apks 扫描，非「换包名即相同」）。
 * <p>
 * SG 3.2.2：dex 内无 {@code com.shopee.shpssdk.*}、无 {@code safemode.b/catchs.a/util.c}、
 * 无 {@code jni.utils.d}；风控仅 {@code shpssdkbank}。
 */
public final class MariBankRegionProfile {

    private MariBankRegionProfile() {
    }

    public static boolean isSingapore(String packageName) {
        return MariBankRootBypassHook.PACKAGE_SG.equals(packageName);
    }

    public static boolean isPhilippines(String packageName) {
        return MariBankRootBypassHook.PACKAGE.equals(packageName);
    }

    public static String label(String packageName) {
        if (isSingapore(packageName)) {
            return "SG";
        }
        if (isPhilippines(packageName)) {
            return "PH";
        }
        return "?";
    }

    /** PH SafeMode boolean 类；SG base/split dex 均无，勿 findClass。 */
    public static String[] safeModeBooleanClasses(String packageName) {
        if (isPhilippines(packageName)) {
            return new String[]{
                    "com.shopee.bke.lib.safemode.b",
                    "com.shopee.bke.lib.safemode.catchs.a",
                    "com.shopee.bke.lib.safemode.util.c",
            };
        }
        return new String[0];
    }

    /** 两区共有或 SG 专用 risk 类（classes3.dex）。 */
    public static String[] sharedRiskClasses() {
        return new String[]{"com.shopee.bke.biz.base.risk.a"};
    }

    /** SHPSSDK Java 入口：SG 仅 bank 包。 */
    public static String[] shpsSdkClasses(String packageName) {
        if (isSingapore(packageName)) {
            return new String[]{"com.shopee.shpssdkbank.SHPSSDK"};
        }
        return new String[]{
                "com.shopee.shpssdk.SHPSSDK",
                "com.shopee.shpssdkbank.SHPSSDK",
        };
    }

    public static String[] shpsAssessRiskClasses(String packageName) {
        if (isSingapore(packageName)) {
            return new String[]{"com.shopee.shpssdkbank.SPSAssessRisk"};
        }
        return new String[]{
                "com.shopee.shpssdkbank.SPSAssessRisk",
                "com.shopee.shpssdk.SPSAssessRisk",
        };
    }

    public static String[] shpsCallbackAdapterClasses(String packageName) {
        if (isSingapore(packageName)) {
            return new String[]{"com.shopee.shpssdkbank.SPSCallbackAdapter"};
        }
        return new String[]{
                "com.shopee.shpssdk.SPSCallbackAdapter",
                "com.shopee.shpssdkbank.SPSCallbackAdapter",
        };
    }

    /** attestation / native-core：SG 无 com.shopee.shpssdk.wvvvuwwu。 */
    public static String[] shpsAttestationCoreClasses(String packageName) {
        if (isSingapore(packageName)) {
            return new String[]{
                    "com.shopee.shpssdkbank.wvvvuwwu",
                    "com.shopee.shpssdkbank.uwuvuvvww.uvwuuuuuw.vvvvuwwvu",
                    "com.shopee.shpssdkbank.uwuvuvvww.vvuuuuvvv",
                    "com.shopee.shpssdkbank.uwuvuvvww.wvvuuwvwu",
                    "com.shopee.shpssdkbank.uvuwwuvwv.uvwwuuvvw",
            };
        }
        return new String[]{
                "com.shopee.shpssdkbank.wvvvuwwu",
                "com.shopee.shpssdkbank.uwuvuvvww.uvwuuuuuw.vvvvuwwvu",
                "com.shopee.shpssdkbank.uwuvuvvww.vvuuuuvvv",
                "com.shopee.shpssdkbank.uwuvuvvww.wvvuuwvwu",
                "com.shopee.shpssdk.wvvvuwwu",
        };
    }

    /** 加密 JNI：PH 有 utils.d 包装；SG 仅 uvwuvwuv + uvwwwwuv（classes6.dex）。 */
    public static boolean hasEncryptWrapperD(String packageName) {
        return isPhilippines(packageName);
    }

    public static boolean hasEncryptHelperUvwwwwuv(String packageName) {
        return isSingapore(packageName);
    }

    /** late hooks 完成条件：SG 不依赖 PH safemode booleanHooks。 */
    public static boolean isLateHooksReady(
            String packageName, int booleanHooks, int encryptHooks, int attestHooks) {
        if (isSingapore(packageName)) {
            return encryptHooks > 0 || attestHooks > 0;
        }
        return booleanHooks > 0 || encryptHooks > 0 || attestHooks > 0;
    }

    public static boolean isShpssdkLegacyPackage(String className) {
        return className != null
                && className.startsWith("com.shopee.shpssdk.")
                && !className.startsWith("com.shopee.shpssdkbank.");
    }
}
