package com.abbidot.tracker.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.abbidot.baselibrary.constant.MMKVKey
import com.abbidot.baselibrary.util.MMKVUtil
import com.abbidot.tracker.base.BaseActivity
import com.abbidot.tracker.bean.HomeDataBean
import com.abbidot.tracker.bean.PetBean
import com.abbidot.tracker.retrofit2.NetworkApi
import kotlinx.coroutines.launch

/**
 *Created  by .yzq on 2022/3/11/011.
 * @link
 * @description:
 */
class DataViewModel : ViewModel() {

    val mHomePetLiveData = MutableLiveData<Result<MutableList<PetBean>>>()
    val mHomeDataLiveData = MutableLiveData<Result<HomeDataBean>>()

    /**
     * 获取宠物数据
     */
    fun getHomeBindPetList(activity: BaseActivity<*>) {
        activity.showLoading(true, cancelable = false)
        getHomeBindPetList()
    }

    /**
     * 获取宠物数据
     */
    fun getHomeBindPetList() {
        val userId = MMKVUtil.getString(MMKVKey.UserId)
        viewModelScope.launch {
            val result = NetworkApi.getHomeBindPetList(userId)
            mHomePetLiveData.value = result
        }
    }

    /**
     * 获取首页Data模块的设备数据
     */
    fun getHomeDeviceData(deviceId: String, dayTime: String, petId: String) {
        viewModelScope.launch {
            val result = NetworkApi.getDeviceData(deviceId, dayTime, petId)
            mHomeDataLiveData.value = result
        }
    }

}