package com.zj365.mime.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.EtFenceListBean
import com.xty.network.model.RespBody
import org.json.JSONObject

class ElectronicFenceSettingVm : BaseVm() {

    val electronicFenceListLiveDate by lazy { MutableLiveData<RespBody<EtFenceListBean>>() }

    val addOrDeleteLiveData by lazy { MutableLiveData<RespBody<Any>>() }

    fun getElectronicFenceList(){
        startHttp {
            var response = apiInterface().getBtFenceList()
            response.getCodeStatus(electronicFenceListLiveDate, nowData)
        }
    }

    fun setBtFence(title:String,radius:Int, type:Int, log:Double,lat:Double,id:Long?){
        startHttp {
            var json = JSONObject()
            json.put("title",title)
            json.put("radius",radius)
            json.put("type",type)
            json.put("log",log)
            json.put("lat",lat)
            id?.let {
                json.put("id",id)

            }
            var  response = apiInterface().setBtFence(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(addOrDeleteLiveData, nowData)

        }
    }

    fun deleteBtFence(id:Long){
        startHttp {
            var  json = JSONObject()
            json.put("id",id)
            var  response = apiInterface().deleteBtFence(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(addOrDeleteLiveData, nowData)

        }
    }
}