package com.miraclegarden.smsmessage.xposed;

import com.miraclegarden.smsmessage.xposed.hook.MariBankRootBypassHook;
import com.miraclegarden.smsmessage.xposed.hook.MariBankShpsNativeHook;
import com.miraclegarden.smsmessage.xposed.hook.SuncorpBankMessageHook;
import com.miraclegarden.smsmessage.xposed.hook.SqliteMessageHook;
import com.miraclegarden.smsmessage.xposed.hook.TelegramMessageHook;
import com.miraclegarden.smsmessage.xposed.hook.UpBankMessageHook;
import com.miraclegarden.smsmessage.xposed.hook.UbankMessageHook;
import com.miraclegarden.smsmessage.xposed.hook.WeChatMessageHook;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class MainHook implements IXposedHookLoadPackage {

    private static final String WECHAT_PACKAGE = "com.tencent.mm";
    private static final String TELEGRAM_PACKAGE = "org.telegram.messenger";
    private static final String TELEGRAM_WEB_PACKAGE = "org.telegram.messenger.web";
    private static final String UP_BANK_PACKAGE = "au.com.up.money";
    private static final String SUNCORP_PACKAGE = "au.com.suncorp.marketplace";
    private static final String UBANK_PACKAGE = "au.com.bank86400";
    private static final String MAIN_APP_PACKAGE = "com.miraclegarden.smsmessage";

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (lpparam == null || lpparam.packageName == null) {
            return;
        }
        if (MAIN_APP_PACKAGE.equals(lpparam.packageName)) {
            return;
        }

        if (WECHAT_PACKAGE.equals(lpparam.packageName)) {
            WeChatMessageHook.install(lpparam);
            return;
        }

        if (TELEGRAM_PACKAGE.equals(lpparam.packageName)
                || TELEGRAM_WEB_PACKAGE.equals(lpparam.packageName)) {
            TelegramMessageHook.install(lpparam);
            return;
        }

        if (UP_BANK_PACKAGE.equals(lpparam.packageName)) {
            UpBankMessageHook.install(lpparam);
            return;
        }

        if (SUNCORP_PACKAGE.equals(lpparam.packageName)) {
            SuncorpBankMessageHook.install(lpparam);
            return;
        }

        if (UBANK_PACKAGE.equals(lpparam.packageName)) {
            UbankMessageHook.install(lpparam);
            return;
        }

        if (MariBankRootBypassHook.isTargetPackage(lpparam.packageName)) {
            MariBankShpsNativeHook.install(lpparam);
            MariBankRootBypassHook.install(lpparam);
            return;
        }

        SqliteMessageHook.install(lpparam);
    }
}
