import axios, { AxiosInstance } from 'axios' const API_BASE = 'http://localhost:8001/api/v1' const api: AxiosInstance = axios.create({ baseURL: API_BASE, headers: { 'Content-Type': 'application/json', }, }) export interface Alert { id: string source: string title: string description?: string severity: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' | 'INFO' status: 'NEW' | 'ACKNOWLEDGED' | 'RESOLVED' | 'SUPPRESSED' affected_service?: string[] tags?: string[] created_at: string updated_at: string } export interface Incident { id: string title: string status: 'OPEN' | 'IN_PROGRESS' | 'RESOLVED' | 'CLOSED' severity: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' created_at: string updated_at: string } export interface SystemStats { total_incidents: number open_incidents: number total_alerts: number avg_mttr_minutes: number | null } export const alertsApi = { // Get all alerts getAlerts: (page = 1, perPage = 20) => api.get<{ items: Alert[]; total: number }>('/alerts', { params: { page, per_page: perPage } }), // Create alert createAlert: (data: Partial) => api.post('/alerts', data), // Get single alert getAlert: (id: string) => api.get(`/alerts/${id}`), // Update alert updateAlert: (id: string, data: Partial) => api.put(`/alerts/${id}`, data), // Delete alert deleteAlert: (id: string) => api.delete(`/alerts/${id}`), } export const incidentsApi = { // Get all incidents getIncidents: (page = 1, perPage = 20) => api.get<{ items: Incident[]; total: number }>('/incidents', { params: { page, per_page: perPage } }), // Create incident createIncident: (data: Partial) => api.post('/incidents', data), // Get single incident getIncident: (id: string) => api.get(`/incidents/${id}`), // Acknowledge incident acknowledgeIncident: (id: string) => api.post(`/incidents/${id}/acknowledge`, {}), // Resolve incident resolveIncident: (id: string) => api.post(`/incidents/${id}/resolve`, {}), } export const healthApi = { // Health check getHealth: () => api.get('/health'), // System stats getStats: () => api.get('/stats'), }