package waific.Teflonic.therapistic

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import tooic.fatalityic.Runawayic.isScoreRated
import negligentlyic.wrongic.bottomic.Timidic.getRecycleBinData
import tooic.fatalityic.redic.speckledic.hankeringic.Oustic.checkNotificationPermission
import tooic.fatalityic.redic.speckledic.hankeringic.Oustic.checkStorePermission
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.io.File

class Transitionalic : 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()) {
            dialogFlow.update { "NotificationDialog" }
            return
        }

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

    var recycleBinFileFlow: MutableStateFlow<List<File>> = MutableStateFlow(listOf())

    fun refreshRecycleBin() = viewModelScope.launch(Dispatchers.IO) {
        recycleBinFileFlow.update { getRecycleBinData() }
    }
}