import type { DetectStatisticsModel, WarningStatisticsModel, SecurityAlertModel, SecurityCameraModel } from './model';

import type { BaseResult } from '#/api/base-result';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

// API路径常量枚举
enum Api {
  // 检测统计
  detectStatistics = '/security/statistics/detect',
  // 预警分类统计
  warningStatistics = '/security/statistics/warning',
  
  // 预警记录相关
  alertRoot = '/securityAlert/alert',
  alertList = '/securityAlert/alert/list',
  alertExport = '/securityAlert/alert/export',
  alertHandle = '/securityAlert/alert/handle',
  
  // 摄像头设备相关
  cameraRoot = '/securityCamera/camera',
  cameraList = '/securityCamera/camera/list',
  cameraExport = '/securityCamera/camera/export',
}

/**
 * 查询检测统计
 * @returns 检测统计结果
 */
export function getDetectStatistics() {
  return requestClient.get<BaseResult<DetectStatisticsModel>>(Api.detectStatistics);
}

/**
 * 查询每个分类的预警未处理数量
 * @returns 预警分类统计结果
 */
export function getWarningStatistics() {
  return requestClient.get<BaseResult<WarningStatisticsModel[]>>(Api.warningStatistics);
}

/**
 * 查询预警记录列表
 * @param params 查询参数
 * @returns 预警记录列表
 */
export function getSecurityAlertList(params: any) {
  return requestClient.get<BaseResult<SecurityAlertModel[]>>(Api.alertList, {
    params,
  });
}

/**
 * 获取预警记录详细信息
 * @param alertId 预警ID
 * @returns 预警记录详情
 */
export function getSecurityAlertDetail(alertId: number) {
  return requestClient.get<SecurityAlertModel>(`${Api.alertRoot}/${alertId}`);
}

/**
 * 新增预警记录
 * @param data 预警记录数据
 * @returns 操作结果
 */
export function addSecurityAlert(data: SecurityAlertModel) {
  return requestClient.post(Api.alertRoot, data, {
    successMessageMode: 'message',
  });
}

/**
 * 修改预警记录
 * @param data 预警记录数据
 * @returns 操作结果
 */
export function updateSecurityAlert(data: SecurityAlertModel) {
  return requestClient.put(Api.alertRoot, data, {
    successMessageMode: 'message',
  });
}

/**
 * 删除预警记录
 * @param alertIds 预警ID数组
 * @returns 操作结果
 */
export function deleteSecurityAlert(alertIds: number[]) {
  return requestClient.delete(`${Api.alertRoot}/${alertIds.join(',')}`, {
    successMessageMode: 'message',
  });
}

/**
 * 导出预警记录列表
 * @param data 导出参数
 * @returns 导出结果
 */
export function exportSecurityAlert(data: Partial<SecurityAlertModel>) {
  return commonExport(Api.alertExport, data);
}

/**
 * 处理预警记录
 * @param data 处理参数
 * @returns 操作结果
 */
export function handleSecurityAlert(data: any) {
  return requestClient.put(Api.alertHandle, data, {
    successMessageMode: 'message',
  });
}

/**
 * 查询摄像头设备列表
 * @param params 查询参数
 * @returns 摄像头设备列表
 */
export function getSecurityCameraList(params: any) {
  return requestClient.get<BaseResult<SecurityCameraModel[]>>(Api.cameraList, {
    params,
  });
}

/**
 * 获取摄像头设备详细信息
 * @param cameraId 摄像头ID
 * @returns 摄像头设备详情
 */
export function getSecurityCameraDetail(cameraId: number) {
  return requestClient.get<SecurityCameraModel>(`${Api.cameraRoot}/${cameraId}`);
}

/**
 * 新增摄像头设备
 * @param data 摄像头设备数据
 * @returns 操作结果
 */
export function addSecurityCamera(data: SecurityCameraModel) {
  return requestClient.post(Api.cameraRoot, data, {
    successMessageMode: 'message',
  });
}

/**
 * 修改摄像头设备
 * @param data 摄像头设备数据
 * @returns 操作结果
 */
export function updateSecurityCamera(data: SecurityCameraModel) {
  return requestClient.put(Api.cameraRoot, data, {
    successMessageMode: 'message',
  });
}

/**
 * 删除摄像头设备
 * @param cameraIds 摄像头ID数组
 * @returns 操作结果
 */
export function deleteSecurityCamera(cameraIds: number[]) {
  return requestClient.delete(`${Api.cameraRoot}/${cameraIds.join(',')}`, {
    successMessageMode: 'message',
  });
}

/**
 * 导出摄像头设备列表
 * @param data 导出参数
 * @returns 导出结果
 */
export function exportSecurityCamera(data: Partial<SecurityCameraModel>) {
  return commonExport(Api.cameraExport, data);
}
