package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.common.util.CommonUtils
import com.xty.network.model.*
import org.json.JSONObject

class HistoryDeviceVm: BaseVm() {
    val bindOk by lazy{MutableLiveData<RespBody<PaingBean<BindDevHistoryBean>>>()}
    val bodyFatData by lazy { MutableLiveData<RespBody<PaingBean<BodyFatHistoryBean>>>() }
    val deleteSuccess by lazy { MutableLiveData<RespBody<Any>>() }


    fun deleteDevicesDatas(ids:String){
        startHttp {
            var response =apiInterface().deleteDevicesDatas(ids)
            response.getCodeStatus(deleteSuccess,nowData)
        }
    }

    fun deleteBodyFatDatas(ids:String){
        startHttp {
            var response =apiInterface().deleteBodyFatDatas(ids)
            response.getCodeStatus(deleteSuccess,nowData)
        }
    }

    fun getBodyFatHistory(id:String?,year:String?,month:String?,page:Int){
        startHttp {
            var json=JSONObject()
            json.put("pageNum",page)
            json.put("pageSize", 20)
            json.put("userId",id)
            json.put("year",year)
            json.put("month",month)
            var response =apiInterface().getBodyFatHistoryList(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(bodyFatData,nowData)
        }
    }
    /**
     * 类型，1，血压计，2，血糖仪
     */
    fun getDeviceHistory(userId:String?,deviceType:Int,date:String?,page:Int){
        startHttp {
            var json=JSONObject()
            json.put("userId",userId)
            json.put("pageNum",page)
            json.put("pageSize", 20)
            date?.let {
                json.put("date",date)
            }
            json.put("deviceType",deviceType)
            var response =apiInterface().getHistoryList(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(bindOk,nowData)
        }
    }

}