package com.abbidot.tracker.deprecated.ui.activity.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.abbidot.tracker.base.BaseActivity
import com.abbidot.tracker.bean.MapDeviceBean
import com.abbidot.tracker.retrofit2.NetworkApi
import kotlinx.coroutines.launch

/**
 *Created  by .yzq on 2022/4/9/009.
 * @link
 * @description:
 */
class LedLightViewModel : ViewModel() {

    val mSetLedLightLiveData = MutableLiveData<Result<String>>()
    val mLedSwitchLiveData = MutableLiveData<Result<String>>()

    /**
     * 设置light灯光
     */
    fun setLedLight(activity: BaseActivity<*>, mapDeviceBean: MapDeviceBean, modeType: Int) {
        activity.showLoading(true)
        mapDeviceBean.apply {
            viewModelScope.launch {
                val result = NetworkApi.setLedLight(
                    deviceServerId,
                    ledRedValue,
                    ledGreenValue,
                    ledBlueValue,
                    ledMode,
                    ledSwitch,
                    modeType
                )
                mSetLedLightLiveData.value = result
            }
        }
    }

    /**
     * 设置ledSwitch开关
     */
    fun setLedSwitch(
        activity: BaseActivity<*>?, deviceInfoId: String, ledSwitch: Int, modeType: Int
    ) {
        activity?.showLoading(true)
        viewModelScope.launch {
            val result = NetworkApi.setLedSwitch(deviceInfoId, ledSwitch, modeType)
            mLedSwitchLiveData.value = result
        }
    }
}