package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.BindDevHistoryBean
import com.xty.network.model.BodyFatHistoryBean
import com.xty.network.model.PaingBean
import com.xty.network.model.RecentlyHealthBean
import com.xty.network.model.RespBody
import org.json.JSONObject

class DevicesChatVm : BaseVm() {

    val getRecentyHealthReturnData by lazy { MutableLiveData<RespBody<RecentlyHealthBean>>() }
    val bodyFatData by lazy { MutableLiveData<RespBody<PaingBean<BodyFatHistoryBean>>>() }
    val bindOk by lazy{MutableLiveData<RespBody<PaingBean<BindDevHistoryBean>>>()}

    fun getChatData(
        userId: String,
        dataType: String
    ) {
        val json = JSONObject()
        json.put("userId", userId)
        json.put("deviceType", dataType)
        startHttp {
            val recentlyHealth =
                apiInterface().getChatData(retrofits.getRequestBody(json.toString()))
            recentlyHealth.getCodeStatus(getRecentyHealthReturnData, 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)
        }
    }

    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)
        }
    }

}