import { request } from '@/api/request'

/** 获取 当前告警记录列表 */
export const fetchAlertRecords = (data: {
  page?: number
  page_size?: number
  policy_id?: number
  rule_id?: number
  status?: string
  severity_id?: number
  start_time?: string
  end_time?: string
  keyword?: string
  sort?: string
  order?: string
  binding_id?: number
  resource_category?: string
  server_identity?: string
  ip?: string
}) => {
  return request.get('/Alert/v1/record/list', { params: data })
}

/** 获取 告警记录详情 */
export const fetchAlertRecordDetail = (id: number) => request.get(`/Alert/v1/record/get/${id}`)

/** 创建处理记录（执行确认/解决/屏蔽等操作） */
export const createAlertProcess = (data: {
  alert_record_id: number
  action: string // ack / resolve / silence / comment / assign / escalate / close
  comment?: string
  assign_to?: string
  assign_to_id?: string
  silence_until?: string
  silence_reason?: string
  escalate_level?: string
  escalate_to?: string
  root_cause?: string
  solution?: string
  // 按后端约定：metadata 为 JSON 字符串，例如 "{}"
  metadata?: string
}) => request.post('/Alert/v1/process/create', data)

/** 获取 告警处理记录列表 */
export const fetchAlertProcessList = (data: {
  alert_record_id?: number
  action?: string
  page?: number
  page_size?: number
  keyword?: string
  sort?: string
  order?: string
}) => request.get('/Alert/v1/process/list', { params: data })
