package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.common.util.CommonToastUtils
import com.xty.network.model.EnableTime
import com.xty.network.model.OnLineTime
import com.xty.network.model.RespBody
import org.json.JSONObject

class OnLineMakeVm: BaseVm() {
    val timeData by lazy { MutableLiveData<RespBody<OnLineTime>>()}
    val submitData by lazy { MutableLiveData<RespBody<String>>()}

    val timeLive by lazy{MutableLiveData<RespBody<MutableList<EnableTime>>>()}

    fun getTimeReservation(id:String){
        startHttp {
          var body=  apiInterface().getTimeReservation(id)
            body.getCodeStatus(timeData,nowData)
        }
    }

    fun  getNowDataEnable(id: String,date:String){
        startHttp {
           var response= apiInterface().getNowDataEnable(id,date)
            response.getCodeStatus(timeLive,nowData)
        }
    }


    fun addReservation(butlerId:String,startTime:String,reservationDate:String,weekNum:Int,userName:String,phone:String,remark:String){
        if(weekNum==-1){
            CommonToastUtils.showToast("请选择预约时间")
            return
        }
        if(userName.isNullOrEmpty()){
            CommonToastUtils.showToast("请输入预约人姓名")
            return
        }
        if(phone.isNullOrEmpty()){
            CommonToastUtils.showToast("请输入预约电话")
            return
        }
        startHttp {
            var json=JSONObject()
            json.put("butlerId",butlerId)
            json.put("startTime",reservationDate)
            json.put("reservationDate",startTime)
            json.put("weekNum",weekNum)
            var jsonUser=JSONObject()
            jsonUser.put("userName",userName)
            jsonUser.put("userPhone",phone)
            jsonUser.put("remark",remark)
            json.put("info",jsonUser)
          var body=  apiInterface().addReservation(retrofits.getRequestBody(json.toString()))
            body.getCodeStatus(submitData,nowData)
        }
    }
}