import request from '@/utils/request';
import type {
  AlarmHandleResultVO,
  AlarmOverviewSummaryVO,
  EmsActionResponse,
  EmsDetailResponse,
  EmsRecordAlarmDataVO,
  EmsId,
  EmsIdParam,
  EmsListResponse,
  EmsQuery,
  RealtimeAlarmBatchResultVO
} from '../types';

// 查询异常数据记录列表
export function listRecordAlarmData(query?: EmsQuery): Promise<EmsListResponse<EmsRecordAlarmDataVO>> {
  return request({
    url: '/ems/record/recordAlarmData/list',
    method: 'get',
    params: query
  });
}

// 查询异常数据记录详细
export function getRecordAlarmData(objId: EmsId): Promise<EmsDetailResponse<EmsRecordAlarmDataVO>> {
  return request({
    url: '/ems/record/recordAlarmData/' + objId,
    method: 'get'
  });
}

// 查询报警中心统计概览
export function getRecordAlarmDataSummary(query?: EmsQuery): Promise<EmsDetailResponse<AlarmOverviewSummaryVO>> {
  return request({
    url: '/ems/record/recordAlarmData/summary',
    method: 'get',
    params: query
  });
}

// 新增异常数据记录
export function addRecordAlarmData(data: EmsRecordAlarmDataVO): Promise<EmsActionResponse<EmsRecordAlarmDataVO>> {
  return request({
    url: '/ems/record/recordAlarmData',
    method: 'post',
    data: data
  });
}

// 修改异常数据记录
export function updateRecordAlarmData(data: EmsRecordAlarmDataVO): Promise<EmsActionResponse<EmsRecordAlarmDataVO>> {
  return request({
    url: '/ems/record/recordAlarmData',
    method: 'put',
    data: data
  });
}

// 删除异常数据记录
export function delRecordAlarmData(objId: EmsIdParam): Promise<EmsActionResponse> {
  return request({
    url: '/ems/record/recordAlarmData/' + objId,
    method: 'delete'
  });
}

// 确认处理异常数据记录
export function handleExceptions(objId: EmsId): Promise<EmsActionResponse<AlarmHandleResultVO>> {
  return request({
    url: '/ems/record/recordAlarmData/handleExceptions/' + objId,
    method: 'post'
  });
}

// 查询异常数据记录列表
export function getAlarmDataTotalCount(): Promise<EmsDetailResponse<number>> {
  return request({
    url: '/ems/record/recordAlarmData/getAlarmDataTotalCount',
    method: 'get'
  });
}

// 保存WebSocket告警数据（批量保存）
// 参数alarmDataList应为EmsRecordAlarmData实体数组
// 每个告警规则对应一条EmsRecordAlarmData记录
export function saveWebSocketAlarmData(alarmDataList: EmsRecordAlarmDataVO[]): Promise<EmsActionResponse<RealtimeAlarmBatchResultVO>> {
  return request({
    url: '/ems/record/recordAlarmData/saveWebSocketAlarmData',
    method: 'post',
    data: alarmDataList // 传递EmsRecordAlarmData实体数组
  });
}
