import request from '@/utils/request'
import constant from '@/constant'

function pageList(formData){
  return request.post(constant.serverUrl + "/base/electricClientInfo/pageList", formData);
}

function create(){
  return request.get(constant.serverUrl + "/base/electricClientInfo/create");
}

function edit(id){
  return request.get(constant.serverUrl + "/base/electricClientInfo/edit/" + id);
}

function syncDevice(id){
  return request.get(constant.serverUrl + `/base/electricClientInfo/syncDevice?id=${id}`);
}

function add(formModel){
  return request.post(constant.serverUrl + "/base/electricClientInfo/add", formModel,{
    headers: {
      "Content-Type": "application/json"
    }
  });
}

function update(formModel){  
  return request.post(constant.serverUrl + "/base/electricClientInfo/update", formModel,{
    headers: {
      "Content-Type": "application/json"
    }
  });
}

function remove(id){
  return request.post(constant.serverUrl + "/base/electricClientInfo/delete/" + id);
}

function batchRemove(idList){
  return request.post(constant.serverUrl + "/base/electricClientInfo/batchDelete",idList,{
    headers: {
      "Content-Type": "application/json"
    }
  });
}

function powerSwitch(roomId,cmd){
  var formData = new FormData();
  
  formData.append("roomId", roomId);
  formData.append("cmd", cmd);

  return request.post(constant.serverUrl + "/base/electricClientInfo/powerSwitch", formData);
}

export default {
  pageList,create,edit,add,update,remove,batchRemove, powerSwitch,syncDevice
}