import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AlarmDetailQuery, AlarmDetailVO, AlarmRuleForm, AlarmRuleQuery, AlarmRuleVO, BindAlarmRuleDevicesForm } from './types';

export const listAlarmRule = (query?: AlarmRuleQuery): AxiosPromise<AlarmRuleVO[]> => {
  return request({
    url: '/ems/alarmRule/list',
    method: 'get',
    params: query
  });
};

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

export const addAlarmRule = (data: AlarmRuleForm) => {
  return request({
    url: '/ems/alarmRule',
    method: 'post',
    data
  });
};

export const updateAlarmRule = (data: AlarmRuleForm) => {
  return request({
    url: '/ems/alarmRule',
    method: 'put',
    data
  });
};

export const bindAlarmRuleDevices = (data: BindAlarmRuleDevicesForm) => {
  return request({
    url: '/ems/alarmRule/bindDevices',
    method: 'put',
    data
  });
};

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

export const scanAlarmRule = () => {
  return request({
    url: '/ems/alarmRule/scan',
    method: 'post'
  });
};

export const listAlarmDetail = (query?: AlarmDetailQuery): AxiosPromise<AlarmDetailVO[]> => {
  return request({
    url: '/ems/alarmDetail/list',
    method: 'get',
    params: query
  });
};

export const handleAlarmDetail = (data: { id: string | number; handler?: string; handleInfo?: string }) => {
  return request({
    url: '/ems/alarmDetail/handle',
    method: 'put',
    data
  });
};
