import { apiClient } from "./client";
import type { DashboardAlert } from "../types/models";

/**
 * Fetch recent alerts from dashboard backend (real-time monitoring).
 * For live updates, use useAgentUpdates WebSocket which pushes agent_init with alerts.
 */
export async function getAlerts(limit = 20): Promise<DashboardAlert[]> {
  const response = await apiClient.get<DashboardAlert[]>(
    `/api/alerts?limit=${limit}`,
  );
  return response.data;
}

export async function acknowledgeAlert(
  alertId: string,
): Promise<{ status: string }> {
  const response = await apiClient.post<{ status: string }>(
    `/api/alerts/${alertId}/acknowledge`,
  );
  return response.data;
}
