package com.jishisongfu.duobibi.push

import android.content.Context
import android.util.Log
import com.jishisongfu.duobibi.util.PrivacyPrefs
import com.xiaomi.mipush.sdk.MiPushClient

/**
 * 小米推送注册的统一入口。两个调用点:
 *   1) [com.jishisongfu.duobibi.DuobibiApplication.onCreate] — 覆盖"已同意过的老用户冷启动"
 *   2) [com.jishisongfu.duobibi.MainActivity] 隐私 onAgree 回调 — 覆盖"首次安装同意"
 *
 * 抽到一处避免 AppID/AppKey 散落两份在轮换时漏改。隐私 gate 也统一判定。
 *
 * register 是异步的,首启拿到 regId 通常 1-30s,在 [MiPushReceiver.onReceiveRegisterResult]
 * 触发并打 DUOBIBI-PUSH tag log。
 */
object MiPushBootstrap {

    private const val TAG = "DUOBIBI-PUSH"

    // AppID 19 位超过 Long 范围,SDK 接收 String,不能改 Long
    private const val APP_ID = "2882303761520520291"
    private const val APP_KEY = "5602052076291"

    fun registerIfReady(context: Context) {
        if (!PrivacyPrefs.agreed(context)) {
            Log.i(TAG, "register skipped: privacy not agreed yet")
            return
        }
        MiPushClient.registerPush(context.applicationContext, APP_ID, APP_KEY)
        Log.i(TAG, "MiPushClient.registerPush() called")
    }
}
