package com.base.appzxhy.ui.main

import android.content.Context
import androidx.lifecycle.ViewModel
import com.base.appzxhy.SpConstObject.isScoreRated
import com.base.appzxhy.utils.PermissionUtils.areNotificationsEnabled
import com.base.appzxhy.utils.PermissionUtils.checkNotificationPermission
import com.base.appzxhy.utils.PermissionUtils.checkStorePermission
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update

class MainViewModel : ViewModel() {

    var dialogFlow: MutableStateFlow<String> = MutableStateFlow("")
    var nextShowDialog: Boolean = true

    fun checkDialog(context: Context) {

        if (!nextShowDialog) {
            nextShowDialog = true
            return
        }

        if (!context.checkStorePermission()) {
            dialogFlow.update { "StoreDialog" }
            return
        }

        if (
            !context.checkNotificationPermission() ||
            !context.areNotificationsEnabled()
        ) {
            dialogFlow.update { "NotificationDialog" }
            return
        }

        if (!isScoreRated) {
            dialogFlow.update { "RateDialog" }
            return
        }
    }
}