import request from '@/utils/request'

// 查询设备列表
export function listDevice(query) {
  return request({
    url: '/system/device/list',
    method: 'get',
    params: query
  })
}

// ids查询设备列表
export function listDeviceByIds(ids) {
  return request({
    url: `/system/device/listByIds/${ids}`,
    method: 'get',
  })
}

// 查询设备详细
export function getDevice(deviceId) {
  return request({
    url: '/system/device/' + deviceId,
    method: 'get'
  })
}

// 新增设备
export function addDevice(data) {
  return request({
    url: '/system/device',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateDevice(data) {
  return request({
    url: '/system/device',
    method: 'put',
    data: data
  })
}

// 修改设备SN
export function updateDeviceSn(deviceId, sn) {
  return request({
    url: `/system/device/${deviceId}/bindSn/${sn}`,
    method: 'put'
  })
}

// 删除设备
export function delDevice(deviceId) {
  return request({
    url: '/system/device/' + deviceId,
    method: 'delete'
  })
}


// 逻辑删除设备
export function logicDelDevice(deviceId) {
  return request({
    url: '/system/device/logic/' + deviceId,
    method: 'delete'
  })
}


// 刷新物联网设备信息
export function refreshIot(deviceId, onlineType) {
  return request({
    url: `/system/device/${deviceId}/refreshIot`,
    method: 'get',
    timeout: 20000,
    params: {
      onlineType
    }
  })
}

// 添加时长
export function addTime(deviceId, amount, timeUnit) {
  return request({
    url: `/system/device/addTime/${deviceId}`,
    method: 'put',
    params: {
      amount,
      timeUnit
    }
  })
}

// 添加电量
export function addEle(deviceId, amount) {
  return request({
    url: `/system/device/addEle/${deviceId}`,
    method: 'put',
    params: {
      amount
    }
  })
}

// 时长归零
export function resetDevice(deviceId) {
  return request({
    url: `/system/device/${deviceId}/reset`,
    method: 'put'
  })
}

// 电量归零
export function resetEleDevice(deviceId) {
  return request({
    url: `/system/device/${deviceId}/resetEle`,
    method: 'put'
  })
}

// 批量修改型号
export function batchUpdateModel(deviceIds, modelId) {
  return request({
    url: `/system/device/batchUpdateModel`,
    method: 'put',
    data: {
      deviceIds,
      modelId
    }
  })
}

// 设备开关
export function switchDevice(deviceId, open) {
  return request({
    url: `/system/device/${deviceId}/switch?open=${open}`,
    method: 'put'
  })
}

// 强制解绑设备商户
export function unbind(deviceId) {
  return request({
    url: `/system/device/${deviceId}/unbind`,
    method: 'delete'
  })
}

// 绑定设备商户
export function bindMch(deviceId, mchId) {
  return request({
    url: `/system/device/${deviceId}/bindMch`,
    method: 'put',
    params: {
      mchId
    }
  })
}

// 绑定设备代理商
export function bindAgent(deviceId, agentId, agentServiceRate) {
  return request({
    url: `/system/device/${deviceId}/bindAgent`,
    method: 'put',
    params: {
      agentId,
      agentServiceRate
    }
  })
}

// 强制解绑设备代理商
export function unbindAgent(deviceId) {
  return request({
    url: `/system/device/${deviceId}/unbindAgent`,
    method: 'delete'
  })
}

// 更新设备服务费
export function updateDeviceServiceRate(deviceId, serviceRate) {
  return request({
    url: `/system/device/updateServiceRate`,
    method: 'put',
    data: {
      deviceId,
      serviceRate
    }
  })
}

// 远程配网
export function deviceSetWifi(data) {
  return request({
    url: "/system/device/setWifi",
    method: 'put',
    data
  })
}

// 初始化总用电量
export function deviceInitTotalEle(deviceId) {
  return request({
    url: `/system/device/${deviceId}/initTotalEle`,
    method: 'put'
  })
}
