import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MeasuringDeviceForm, MeasuringDeviceQuery, MeasuringDeviceVO } from './types';

export const listMeasuringDevice = (params?: MeasuringDeviceQuery): AxiosPromise<MeasuringDeviceVO[]> => {
  return request({
    url: '/ems/measuringDevice/list',
    method: 'get',
    params
  });
};

export const getMeasuringDevice = (id: string | number): AxiosPromise<MeasuringDeviceVO> => {
  return request({
    url: '/ems/measuringDevice/' + id,
    method: 'get'
  });
};

export const addMeasuringDevice = (data: MeasuringDeviceForm) => {
  return request({
    url: '/ems/measuringDevice',
    method: 'post',
    data
  });
};

export const updateMeasuringDevice = (data: MeasuringDeviceForm) => {
  return request({
    url: '/ems/measuringDevice',
    method: 'put',
    data
  });
};

export const mountMeasuringDeviceChildren = (data: { parentDeviceGroupId: string | number; childIds: Array<string | number> }) => {
  return request({
    url: '/ems/measuringDevice/mountChildren',
    method: 'put',
    data
  });
};

export const unmountMeasuringDeviceChild = (data: { parentDeviceGroupId: string | number; childId: string | number }) => {
  return request({
    url: '/ems/measuringDevice/unmountChild',
    method: 'put',
    data
  });
};

export const delMeasuringDevice = (ids: string | number | Array<string | number>) => {
  return request({
    url: '/ems/measuringDevice/' + ids,
    method: 'delete'
  });
};
