package com.base.datarecovery.fcm.alarm

import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.base.datarecovery.BuildConfig
import com.base.datarecovery.fcm.NotificationUtil
import com.base.datarecovery.utils.AppPreferences
import com.base.datarecovery.utils.EventUtils
import com.base.datarecovery.utils.LogEx

class AlarmJobReceiver : BroadcastReceiver() {

    private val TAG = "AlarmJobReceiver"

    @SuppressLint("UnsafeProtectedBroadcastReceiver")
    override fun onReceive(context: Context, intent: Intent?) {
        LogEx.logDebug(TAG, "AlarmJobReceiver onReceive")
        EventUtils.event("alarm_push")
        var firstAlemtime = AppPreferences.getInstance().getLong("firstAlemtime", 0L)
        if (BuildConfig.DEBUG) {
            firstAlemtime = 1
        }
        if (firstAlemtime > 0) {
            val leatTime = System.currentTimeMillis()
            if (leatTime - firstAlemtime >= 1000 * 30 * 60) {
                NotificationUtil.sendNotification(context, "alarm");
            }
        }
        AppPreferences.getInstance().put("firstAlemtime", System.currentTimeMillis())
        return
    }
}