import client from '../client'; import type { PaginatedResponse } from '../types'; // --- Types --- export interface Alert { id: string; patient_id: string; rule_id: string; severity: string; title: string; detail?: Record; status: string; acknowledged_by?: string; acknowledged_at?: string; resolved_at?: string; created_at: string; version: number; } export interface AlertRule { id: string; name: string; description?: string; device_type: string; condition_type: string; condition_params: Record; severity: string; is_active: boolean; apply_tags?: Record; notify_roles: unknown[]; cooldown_minutes: number; created_at: string; updated_at: string; version: number; } export interface CreateAlertRuleReq { name: string; description?: string; device_type: string; condition_type: string; condition_params: Record; severity?: string; apply_tags?: Record; notify_roles?: unknown[]; cooldown_minutes?: number; } export interface UpdateAlertRuleReq { name?: string; description?: string; condition_params?: Record; severity?: string; apply_tags?: Record; notify_roles?: unknown[]; cooldown_minutes?: number; version: number; } // --- Alert API --- export async function listAlerts(params?: { patient_id?: string; status?: string; page?: number; page_size?: number; }) { const res = await client.get('/health/alerts', { params }); return res.data.data as PaginatedResponse; } export async function acknowledgeAlert(id: string, version: number) { const res = await client.put(`/health/alerts/${id}/acknowledge`, { version }); return res.data.data as Alert; } export async function dismissAlert(id: string, version: number) { const res = await client.put(`/health/alerts/${id}/dismiss`, { version }); return res.data.data as Alert; } export async function resolveAlert(id: string, version: number) { const res = await client.put(`/health/alerts/${id}/resolve`, { version }); return res.data.data as Alert; } // --- Alert Rule API --- export async function listAlertRules(params?: { device_type?: string; page?: number; page_size?: number; }) { const res = await client.get('/health/alert-rules', { params }); return res.data.data as PaginatedResponse; } export async function createAlertRule(data: CreateAlertRuleReq) { const res = await client.post('/health/alert-rules', data); return res.data.data as AlertRule; } export async function updateAlertRule(id: string, data: UpdateAlertRuleReq) { const res = await client.put(`/health/alert-rules/${id}`, data); return res.data.data as AlertRule; } export async function deactivateAlertRule(id: string, version: number) { const res = await client.put(`/health/alert-rules/${id}/deactivate`, { version }); return res.data.data as AlertRule; }