package com.seven.ikar.kotlin.core.push

import android.content.Context
import com.google.android.gms.tasks.Tasks
import com.google.firebase.messaging.FirebaseMessaging
import java.util.concurrent.TimeUnit

object FirebaseTokenProvider {
    fun tryGetToken(context: Context): String? {
        if (!AndroidPushBootstrapper.tryInitialize(context)) {
            return null
        }

        return runCatching {
            Tasks.await(FirebaseMessaging.getInstance().token, 20, TimeUnit.SECONDS)
        }.getOrNull()
    }
}
