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

export interface Incident {
  id: number
  created_at: string
  updated_at: string
  incident_no: string
  dedup_key: string
  status: string
  severity: string
  resource_uid: string
  business_system_id: number
  owner_user_id: number
  summary: string
  description: string
  labels: string
  annotations: string
  raw_event_id: number
  latest_alert_record_id: number
  alert_count: number
  suppressed: boolean
  suppression_reason: string
  opened_at: string
  assigned_at?: string
  in_progress_at?: string
  suspended_at?: string
  resolved_at?: string
  closed_at?: string
}

export const fetchIncidents = (params: {
  page?: number
  page_size?: number
  keyword?: string
  status?: string
  severity?: string
  resource_uid?: string
  business_system_id?: number
  owner_user_id?: number
  suppressed?: boolean
  sort?: string
  order?: string
}) => request.get('/Alert/v1/incidents/list', { params })

export const fetchIncidentDetail = (id: number) => request.get(`/Alert/v1/incidents/get/${id}`)

export const fetchIncidentAlerts = (id: number) => request.get(`/Alert/v1/incidents/${id}/alerts`)

export const fetchIncidentTimeline = (id: number) => request.get(`/Alert/v1/incidents/${id}/timeline`)

export const transitionIncident = (id: number, data: { status: string; comment?: string }) =>
  request.post(`/Alert/v1/incidents/${id}/transition`, data)
