package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.XdBean
import com.xty.network.model.RespBody
import com.xty.network.model.XdInfoBean
import okhttp3.MultipartBody
import org.json.JSONObject
import java.io.File

class XdVm: BaseVm() {
    val uploadLive by lazy{MutableLiveData<RespBody<MutableList<XdInfoBean>>>()}
    val uploadXd by lazy{MutableLiveData<RespBody<String>>()}
    val xdLive by lazy{MutableLiveData<RespBody<XdBean>>()}




    fun uploadXdInfo(file:String,state:String,hr:String,hrv:String,dbp:String){
        startHttp {
            var files=File(file)

            var fileBody=  MultipartBody.Part.createFormData("file",files.name,retrofits.getMultiPartFileRb(files))
            var hrBody=retrofits.getRequestBody(hr)
            var hrvBody=retrofits.getRequestBody(hrv)
            var dbpBody=retrofits.getRequestBody(dbp)
            var statusBody=retrofits.getRequestBody(state)
            var response=  apiInterface().uploadXmInfo(fileBody,hrvBody,hrBody,dbpBody,statusBody)
            response.getCodeStatus(uploadXd,nowData)
        }
    }

    fun getXdHistory(id:String){
        startHttp {
            var json=JSONObject()
            json.put("userId",id)
         var history= apiInterface().getXdHistory(retrofits.getRequestBody(json.toString()))
            history.getCodeStatus(uploadLive,nowData)

        }
    }
    fun uploadXmInfo(name:String){
        startHttp {
         var history= apiInterface().getXdDesc(name)
            history.getCodeStatus(xdLive,nowData)

        }
    }
}