package com.base.easyfilemanager.display.fcm

import android.util.Log
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import com.google.firebase.messaging.FirebaseMessaging


object FcmHelper {

    private const val TAG = "FcmHelper"

    fun subscribeToTopic() {
        FirebaseMessaging.getInstance().subscribeToTopic("news")
            .addOnCompleteListener { task: Task<Void?> ->
                if (task.isSuccessful) {
                    Log.d(TAG, "Subscribed to topic: TOPIC_NAME")
                } else {
                    Log.e(TAG, "Failed to subscribe to topic: TOPIC_NAME", task.exception)
                }
            }


    }

    fun getToken() {
        FirebaseMessaging.getInstance().token
            .addOnCompleteListener(OnCompleteListener { task ->
                if (!task.isSuccessful) {
                    Log.w(TAG, "Fetching FCM registration token failed", task.exception)
                    return@OnCompleteListener
                }
                // Get new FCM registration token
                val token = task?.result?:""
                Log.d(TAG, "token: $token")
            })
    }

    fun unSubscribeToTopic() {
        FirebaseMessaging.getInstance().unsubscribeFromTopic("news")
            .addOnCompleteListener { task: Task<Void?> ->
                if (task.isSuccessful) {

                } else {

                }
            }
    }
}