package com.convenient.android.common.utils.firebase

import android.content.Context
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/7/29
 * description:Firebase远程配置
 */
object FirebaseRemoteConfig {

    fun initFirebaseConfig(context: Context, callback : (()-> Unit)? = null){
        val configSettings = remoteConfigSettings {
            minimumFetchIntervalInSeconds = 3600
            fetchTimeoutInSeconds = 30
        }

        Firebase.remoteConfig.apply {
            setConfigSettingsAsync(configSettings)

        }.fetchAndActivate().addOnCompleteListener {
            callback?.invoke()
        }
    }

    fun getBoolean(key : String) : Boolean = Firebase.remoteConfig.getBoolean(key)

    fun getString(key: String) : String = Firebase.remoteConfig.getString(key)

    fun getLong(key: String) : Long = Firebase.remoteConfig.getLong(key)

    fun getDouble(key: String) : Double = Firebase.remoteConfig.getDouble(key)


}