import request from '@/utils/request';
import type { EquipmentList, DeviceInfoForm } from '@/api/equipmentList/types';
import { AxiosPromise } from 'axios';
import { DemoVO, DemoForm, DemoQuery, DrawFrom } from '@/api/demo/demo/types';
import { AlarmAreaData } from '@/api/equipmentList/types';

/**
 * 新增设备
 * @param data 设备数据
 * @returns AxiosPromise<any>
 */
export const addEquipment = (data: DemoForm) => {
  return request({
    url: '/device/info/add',
    method: 'post',
    data: data
  });
};

/**
 * 查询设备列表
 * @param query 查询参数
 * @returns AxiosPromise<DemoVO[]>
 */
export const getDevicetList = (query: EquipmentList) => {
  return request({
    url: '/device/info/list',
    method: 'get',
    params: query
  });
};

/**
 * 获取设备详情（路径参数 id）
 * @param id 设备主键
 */
export const getDeviceInfo = (id: string | number) => {
  return request({
    url: `/device/info/${id}`,
    method: 'get'
  });
};

/**
 * 删除设备
 * @param ids 设备主键列表（Query：ids=1,2,3）
 */
export const delDevice = (id: string | number | Array<string | number>) => {
  const idsParam = Array.isArray(id) ? id.join(',') : String(id);
  return request({
    url: '/device/info/delete',
    method: 'post',
    params: { ids: idsParam }
  });
};
/**
 * 激活设备
 * @param id 单个主键或主键数组（与删除相同：POST + Query，ids=1,2,3）
 */
export const actDevice = (id: string | number | Array<string | number>) => {
  const idsParam = Array.isArray(id) ? id.join(',') : String(id);
  return request({
    url: '/device/info/activate',
    method: 'post',
    params: { ids: idsParam }
  });
};

/**
 * 编辑设备
 * @param data 设备信息（含 id）
 */
export const updateDeviceInfo = (data: DeviceInfoForm) => {
  return request({
    url: '/device/info/edit',
    method: 'post',
    data
  });
};

/**
 * todo绘制区域
 * @param data 绘制信息数组
 * /haikang/isup/device/motion-detection
 */
export const drawInfo = (data: AlarmAreaData[]) => {
  return request({
    url: '/haikang/isup/device/motion-detection',
    method: 'post',
    data: data
  });
};
