import shutil
import sqlite3
import sys

db_path = sys.argv[1]
apk_path = sys.argv[2]
hook_pkg = "com.miraclegarden.smsmessage.xposed"
scopes = [
    "org.telegram.messenger.web",
    "org.telegram.messenger",
    "com.miraclegarden.smsmessage",
    "sg.com.maribankmobile.digitalbank",
    "ph.seabank.seabank",
    "au.com.up.money",
    "au.com.suncorp.marketplace",
    "au.com.bank86400",
]

shutil.copy2(db_path, db_path + ".bak")
conn = sqlite3.connect(db_path)
c = conn.cursor()

c.execute(
    "INSERT OR REPLACE INTO modules (mid, module_pkg_name, apk_path, enabled, auto_include) "
    "VALUES (?, ?, ?, ?, ?)",
    (2, hook_pkg, apk_path, 1, 0),
)
c.execute("DELETE FROM scope WHERE mid = 2")
for pkg in scopes:
    c.execute(
        "INSERT OR REPLACE INTO scope (mid, app_pkg_name, user_id) VALUES (?, ?, ?)",
        (2, pkg, 0),
    )
conn.commit()
conn.close()
print("configured", hook_pkg, "scopes=", scopes)
