package com.test.basd.fastcleanerjunk.display.fcm

import android.os.Build
import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.test.basd.fastcleanerjunk.display.NotificationUtils
import com.test.basd.fastcleanerjunk.display.fcm.NotificationJobService.Companion.initJob
import com.test.basd.fastcleanerjunk.helps.EventHelper


class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        Log.d(TAG, "onMessageReceived: " + remoteMessage.from)
        val pushStayTime = remoteMessage.data["push_stay_time"]?.toLongOrNull() ?: 0
        EventHelper.event("fcm_message_received", pushStayTime.toString())
        NotificationUtils.sendTimerPush(pushStayTime)


        FcmHelper.getToken()

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            return
        }
        initJob()
    }



    override fun onNewToken(token: String) {
        Log.d(TAG, "Refreshed token: $token")
    }


    companion object {
        private const val TAG = "MyFirebaseMsgService"
    }
}
