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

/** 获取 告警记录列表 */
export const fetchHistories = (data: {
  page?: number
  page_size?: number
  size?: number
  policy_id?: number
  rule_id?: number
  status?: string
  severity_id?: number
  starts_at?: string
  ends_at?: string
  keyword?: string
}) => {
  // 兼容 size 参数，转换为 page_size
  const params: any = { ...data }
  if (params.size !== undefined && params.page_size === undefined) {
    params.page_size = params.size
    delete params.size
  }
  return request.get('/Alert/v1/record/list', { params })
}

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

/** 获取 告警统计 */
export const fetchAlertStatistics = (data: { policy_id?: number; starts_at?: string; ends_at?: string }) =>
  request.get('/Alert/v1/record/statistics', { params: data })

/** 获取 告警计数 */
export const fetchAlertCount = () => request.get('/Alert/v1/record/count')

/** 获取 告警处理记录列表 */
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 })

/** 获取 告警趋势 */
export const fetchAlertTrend = (data: {
  granularity?: string // day / month
  start_time?: string
  end_time?: string
  policy_id?: number
  severity_id?: number
}) => request.get('/Alert/v1/record/trend', { params: data })
