package ru.myitschool.work.ui.splash

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.Lazy
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import ru.myitschool.work.domain.auth.IsLoginUseCase
import ru.myitschool.work.utils.MutablePublishFlow
import javax.inject.Inject

@HiltViewModel
class SplashViewModel @Inject constructor(
    private val isLoginUseCase: Lazy<IsLoginUseCase>,
) : ViewModel() {

    private val _action = MutablePublishFlow<Action>()
    val action = _action.asSharedFlow()

    init {
        viewModelScope.launch {
            if (isLoginUseCase.get().invoke()) {
                _action.emit(Action.OpenProfile)
            } else {
                _action.emit(Action.OpenLogin)
            }
        }
    }

    sealed interface Action {
        data object OpenProfile : Action
        data object OpenLogin : Action
    }
}