import request from "@/utils/request";

const isSim = import.meta.env.MODE === "simulation";

// 批量获取设备详情
export function listPestDevice(query) {
  if (isSim) {
    return Promise.resolve({});
  }

  return request({
    url: "/worm/device/getBtchDeviceDO",
    method: "get",
    params: query,
  });
}

// 修改设备信息
export function editPestDevice(data) {
  return request({
    url: "/worm/device/updateDevice",
    method: "post",
    data,
  });
}

// 获取设备自动模式时间
export function getPestDeviceAutoMode() {
  if (isSim) {
    return Promise.resolve({});
  }

  return request({
    url: "/worm/device/getWormAutoMode",
    method: "get",
  });
}

// 修改设备自动模式时间
export function editPestDeviceAutoMode(data) {
  return request({
    url: "/worm/device/updateWormAutoMode",
    method: "post",
    data,
  });
}

// 切换设备模式
export function changePestDeviceMode(data) {
  return request({
    url: "/worm/device/deviceOper/changeWormMode",
    method: "post",
    data,
  });
}

// 下发命令
export function setCommand(data) {
  return request({
    url: "/worm/device/deviceOper/wormOper",
    method: "post",
    data,
  });
}

// 获取设备历史数据
export function getPestDeviceHistory() {
  if (isSim) {
    return Promise.resolve({});
  }

  return request({
    url: "/worm/device/getWormHistoryData",
    method: "get",
  });
}

// 获取设备统计数据
export function PestGroupStatistics(data = {}) {
  if (isSim) {
    return Promise.resolve({});
  }

  return request({
    url: "/worm/device/getWormGroupStatistics",
    method: "get",
    data,
  });
}

// 获取分析报表
export function getPestDataList(data) {
  if (isSim) {
    return Promise.resolve({});
  }

  return request({
    url: "/worm/device/getWormDataList",
    method: "get",
    data,
  });
}

// 虫害自动识别
export function analysistWorm(id) {
  if (isSim) {
    return Promise.resolve({});
  }

  return request({
    url: `/worm/device/getWormAutoIdentify?recordId=${id}`,
    method: "get",
  });
}

export function getPestRealTimeData(id) {
  if (isSim) {
    return Promise.resolve({
      mode: "0",
      deviceType: "worm",
      insecticideTem: "20℃",
      dryingTem: "20℃",
      rain: "4mm",
      wormFlap: 0,
      insecticide: 0,
      illum: "10lux",
      status: 0,
      shake: "0",
      dryingFlap: 1,
      drying: "1",
      rainFlap: 0,
      moveWorm: 1,
      attractWorm: 0,
      fillLight: 0,
    });
  }

  return request({
    url: `/worm/device/getWormRealTimeData?id=${id}`,
    method: "get",
  });
}
