package com.centralcloud.oncall.sms

import android.content.Context

/**
 * Tiny init helper to bootstrap the SMS-relay subsystem from outside the
 * `sms/` package — call once from `Application.onCreate`:
 *
 *     SmsRelayInit.start(this)
 *
 * This schedules the periodic device heartbeat and the Ops-native push worker
 * if central config has enabled it. The SmsRelayReceiver is registered in
 * AndroidManifest.xml and fires by itself on SMS_RECEIVED, so it doesn't need
 * anything bootstrapped here.
 *
 * The schedule call is idempotent (WorkManager KEEP policy) so calling it
 * every cold start is fine.
 */
object SmsRelayInit {
    fun start(context: Context) {
        DeviceHeartbeatWorker.scheduleIfConfigured(context)
        val prefs = SmsRelayPreferences(context)
        if (prefs.nativePushEnabled) {
            OpsPushWorker.schedule(context)
            OpsPushWorker.enqueueOnce(context)
        }
    }
}
