import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 数据采集信息 */
export interface DeviceData {
          id: number; // id
          deviceType?: string; // device_type
          deviceId?: number; // device_id
          collectedAt?: string | Dayjs; // collected_at
          temperatureC: number; // temperature_c
          currentValue: number; // current_value
          counter1: number; // counter1
          counter2: number; // counter2
          counter1Total: number; // counter1_total
          counter2Total: number; // counter2_total
          analog1: number; // analog1
          analog2: number; // analog2
          analog3: number; // analog3
          analog4: number; // analog4
          analog5: number; // analog5
          analog6: number; // analog6
          analog7: number; // analog7
          f1: number; // 测频1(Hz)
          f2: number; // 测频2(Hz)
          reg1: number; // 从机数据1
          reg2: number; // 从机数据2
          dt: number; // 采样间隔(秒)
          digital1: boolean; // digital1
          digital2: boolean; // digital2
          digital3: boolean; // digital3
          digital4: boolean; // digital4
          digital5: boolean; // digital5
          digital6: boolean; // digital6
          cnReg: boolean; // cn_reg
          doReg: string; // do_reg
          tv: boolean; // tv
          save: boolean; // save
          oee: boolean; // oee
          frameRaw: string; // frame_raw
          isOn: boolean; // 开关状态
          powerW: number; // 功率
  }

// 数据采集 API
export const DeviceDataApi = {
  // 查询数据采集分页
  getDeviceDataPage: async (params: any) => {
    return await request.get({ url: `/iot/device-data/page`, params })
  },

  // 查询数据采集详情
  getDeviceData: async (id: number) => {
    return await request.get({ url: `/iot/device-data/get?id=` + id })
  },

  // 新增数据采集
  createDeviceData: async (data: DeviceData) => {
    return await request.post({ url: `/iot/device-data/create`, data })
  },

  // 修改数据采集
  updateDeviceData: async (data: DeviceData) => {
    return await request.put({ url: `/iot/device-data/update`, data })
  },

  // 删除数据采集
  deleteDeviceData: async (id: number) => {
    return await request.delete({ url: `/iot/device-data/delete?id=` + id })
  },

  /** 批量删除数据采集 */
  deleteDeviceDataList: async (ids: number[]) => {
    return await request.delete({ url: `/iot/device-data/delete-list?ids=${ids.join(',')}` })
  },

  // 导出数据采集 Excel
  exportDeviceData: async (params) => {
    return await request.download({ url: `/iot/device-data/export-excel`, params })
  }
}
