package com.guadou.ewalletrunalone

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import com.guadou.cs_cptservices.YYConstants
import com.guadou.cs_router.YYRouterService
import com.guadou.lib_baselib.base.vm.BaseViewModel
import com.guadou.lib_baselib.engine.SP
import com.guadou.lib_baselib.engine.putString
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltViewModel
class RunAloneViewModel @Inject constructor(
    private val savedStateHandle: SavedStateHandle
) : BaseViewModel() {

    val mLoginSuccessLD = MutableLiveData<Boolean>()

    /**
     * 用户登录-并获取到用户信息-缓存起来
     */
    fun userLogin() {

        launchOnUI {
            loadStartProgress()

            withContext(Dispatchers.IO) {
                SP().putString(YYConstants.SP_KEY_TOKEN, "test")
                YYRouterService.serviceComponentServer?.resetLoginStatus()

                delay(2500)
            }

            loadHideProgress()
            mLoginSuccessLD.value = true
        }

    }

}