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

import com.ys.bdtp.adm.mvvm.model.Response
import com.ys.bdtp.adm.mvvm.model.db.AdmDatabase
import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
import com.ys.bdtp.adm.mvvm.model.nt.Api
import com.ys.bdtp.adm.mvvm.model.request
import com.ys.bdtp.adm.mvvm.model.vo.request.Account
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 闪屏页数据仓库
 *
 * @author bai
 * @param api [Api]
 * @param db [AdmDatabase]
 */
class FlashRepository(private val api: Api, private val db: AdmDatabase) {

    /**
     * 获取当前登录用户
     */
    suspend fun getCurrentUser(): UserEntity? {
        return withContext(Dispatchers.IO) {
            db.userDao().getCurrentUser()
        }
    }

    suspend fun getAccount(): Response<Account> {
        return withContext(Dispatchers.IO) {
            request {
                api.getAccount()
            }
        }
    }

}