import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { RecordAlarmRuleVO, RecordAlarmRuleForm, RecordAlarmRuleQuery } from '@/api/ems/record/types';

/**
 * 查询告警规则列表
 */
export function listRecordAlarmRule(query: RecordAlarmRuleQuery): AxiosPromise<RecordAlarmRuleVO[]> {
  return request({
    url: '/ems/record/recordAlarmRule/list',
    method: 'get',
    params: query
  });
}

/**
 * 查询告警规则详细
 */
export function getRecordAlarmRule(objId: string | number): AxiosPromise<RecordAlarmRuleVO> {
  return request({
    url: '/ems/record/recordAlarmRule/' + objId,
    method: 'get'
  });
}

/**
 * 新增告警规则
 */
export function addRecordAlarmRule(data: RecordAlarmRuleForm): AxiosPromise<any> {
  return request({
    url: '/ems/record/recordAlarmRule',
    method: 'post',
    data: data
  });
}

/**
 * 修改告警规则
 */
export function updateRecordAlarmRule(data: RecordAlarmRuleForm): AxiosPromise<any> {
  return request({
    url: '/ems/record/recordAlarmRule',
    method: 'put',
    data: data
  });
}

/**
 * 删除告警规则
 */
export function delRecordAlarmRule(objId: string | number | Array<string | number>): AxiosPromise<any> {
  return request({
    url: '/ems/record/recordAlarmRule/' + objId,
    method: 'delete'
  });
}

/**
 * 启用/停用告警规则
 */
export function toggleAlarmRule(objId: string | number, isEnabled: number) {
  return request({
    url: '/ems/record/recordAlarmRule/toggle',
    method: 'put',
    data: { objId, isEnabled }
  });
}
