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) {
  return request({
    url: `/system/device/${deviceId}/refreshIot`,
    method: 'get'
  })
}

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

// 时长归零
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 unbindInvestor(deviceId) {
  return request({
    url: `/system/device/${deviceId}/unbindInvestor`,
    method: 'delete'
  })
}

// 投资人绑定设备
export function bindInvestor(deviceId, userId) {
  return request({
    url: `/system/device/bindInvestor`,
    method: 'put',
    params: {
      deviceId,
      userId
    }
  })
}

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