package com.ys.bdtp.adm.mvvm.vm.project

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ys.bdtp.adm.mvvm.model.Data
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
import kotlinx.coroutines.flow.stateIn

/**
 * ProjectViewModel
 *
 * @author bai
 *
 * @param
 */
class ProjectViewModel(private val repo: ProjectRepository) : ViewModel() {

    /**
     * 当前用于和项目
     */
    val userWithsProjects = repo.getUserWithProjects().stateIn(
        scope = viewModelScope,
        started = WhileSubscribed(5000),
        initialValue = Data.loading()
    )

    /**
     * 退出
     */
    suspend fun logout() {
        repo.logout()
    }

}