package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.common.util.CommonToastUtils
import com.zj365.health.R
import com.xty.network.model.BodyFatHistoryBean
import com.xty.network.model.RespBody
import org.json.JSONObject

class BindDeviceVm: BaseVm() {
    val bindDev by lazy { MutableLiveData<RespBody<String>>() }
    val pbfDetail by lazy { MutableLiveData<RespBody<BodyFatHistoryBean>>() }

    fun getPbfInfo (id:String){
        startHttp {
            var response = apiInterface().getPbfInfo(id)
            response.getCodeStatus(pbfDetail, nowData)
        }
    }
    fun bindDev(sn: String) {

        if (sn.isNullOrEmpty()) {
            CommonToastUtils.showToast(R.string.please_scan_device)
            return
        }
        startHttp {
            var json = JSONObject()
            json.put("sn", sn)
            var response = apiInterface().bindDevSn(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(bindDev, nowData)
        }
    }

}