import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeviceVO, DeviceForm, DeviceQuery, DashboardVO } from '@/api/app/device/types';

/**
 * 查询设备信息
列表
 * @param query
 * @returns {*}
 */

export const listDevice = (query?: DeviceQuery): AxiosPromise<DeviceVO[]> => {
  return request({
    url: '/app/device/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询设备信息
详细
 * @param id
 */
export const getDevice = (id: string | number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/app/device/' + id,
    method: 'get'
  });
};

/**
 * 新增设备信息

 * @param data
 */
export const addDevice = (data: DeviceForm) => {
  return request({
    url: '/app/device',
    method: 'post',
    data: data
  });
};

/**
 * 修改设备信息

 * @param data
 */
export const updateDevice = (data: DeviceForm) => {
  return request({
    url: '/app/device',
    method: 'put',
    data: data
  });
};

/**
 * 删除设备信息

 * @param id
 */
export const delDevice = (id: string | number | Array<string | number>) => {
  return request({
    url: '/app/device/' + id,
    method: 'delete'
  });
};

/**
 * 生成设备二维码
 * @param id
 */
export const generateDeviceQrCode = (id: string | number) => {
  return request({
    url: '/app/device/generateQrCode/' + id,
    method: 'post'
  });
};

/**
 * 获取仪表盘数据
 */
export const getDashboard = (): AxiosPromise<DashboardVO> => {
  return request({
    url: '/app/device/dashboard',
    method: 'get'
  });
};
