import { http } from '@/utils/request'

// 预警记录类型
export interface WarningRecord {
  alertId: number
  alertCode: string
  cameraId: number
  detectRecordId: number
  alertType: string
  alertLevel: string
  confidence: number
  snapshotUrl: string
  snapshotPath: string
  alertTime: string
  status: string
  handleUserId: number
  handleTime: string
  handleRemark: string
  location: string
  stationId: number
  stationName: string
  stationManagerId: number
  stationManagerName: string
  stationManagerPhone: string
  areaId: number
  areaManagerId: number
  areaManagerName: string
  areaManagerPhone: string
}

// 预警记录列表请求参数
export interface WarningListParams {
  pageSize?: number
  pageNum?: number
  stationId?: number
  startTime?: string
  endTime?: string
  alertType?: string
}

// 预警记录列表响应
export interface WarningListResponse {
  rows: WarningRecord[]
  total: number
}

// 处理预警记录参数
export interface HandleWarningParams {
  alertId: number
  handleAction: string
  handleContent: string
}

// 查询预警记录列表
export async function getWarningList(params: WarningListParams): Promise<WarningListResponse> {
  const response = await http.get<WarningListResponse>('/securityAlert/alert/list', params)
  return response
}

// 获取预警记录详细信息
export async function getWarningDetail(alertId: number): Promise<WarningRecord> {
  const response = await http.get<WarningRecord>(`/securityAlert/alert/${alertId}`)
  return response
}

// 处理预警记录
export async function handleWarning(params: HandleWarningParams): Promise<void> {
  await http.put('/securityAlert/alert/handle', params)
}

// 获取预警类型映射
export function getAlertTypeMap(): Record<string, string> {
  return {
    fire: '火焰',
    smoke: '烟雾',
    fire_danger: '火灾',
    intrusion: '入侵'
  }
}

// 获取预警级别映射
export function getAlertLevelMap(): Record<string, string> {
  return {
    '1': '一般',
    '2': '重要',
    '3': '紧急'
  }
}

// 获取处理状态映射
export function getStatusMap(): Record<string, string> {
  return {
    unhandled: '未处理',
    handling: '处理中',
    resolved: '已解决',
    false_alarm: '误报'
  }
}

// 获取状态名称
export function getStatusName(status: string): string {
  const statusMap = getStatusMap()
  return statusMap[status] || status
}

// 获取预警类型名称
export function getAlertTypeName(alertType: string): string {
  const alertTypeMap = getAlertTypeMap()
  return alertTypeMap[alertType] || alertType
}

// 获取预警级别名称
export function getAlertLevelName(alertLevel: string): string {
  const alertLevelMap = getAlertLevelMap()
  return alertLevelMap[alertLevel] || alertLevel
}
