package com.base.locationsharewhite.fcm

import android.content.Context
import com.base.locationsharewhite.helper.ConfigHelper
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.KotlinExt.toFormatMinute

object MsgMgr {

    /**
     *  FCM主题订阅 Topic 包名+首次启动的当前的分钟
     */
    private var topic
        get() = AppPreferences.getInstance().getString("topic", "")
        set(value) = AppPreferences.getInstance().put("topic", value)


    fun init(context: Context) {
        FCMManager.initFirebase(context)
        var topic = this.topic
        if (topic.isEmpty()) {
            val topicNumber = System.currentTimeMillis().toFormatMinute()
            topic = ConfigHelper.packageName + "_$topicNumber"
            this.topic = topic
        }
        FCMManager.subscribeToTopic(topic)
    }
}