import { fetchWithAuth } from "./client"; function buildQuery(params: Record): string { const qs = Object.entries(params) .filter(([, v]) => v !== undefined) .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`) .join("&"); return qs ? `?${qs}` : ""; } export interface DetectionTask { id: string; query_id: string; platforms: string[]; frequency: string; status: string; last_run_at: string | null; next_run_at: string | null; created_at: string; } export interface DetectionTaskList { items: DetectionTask[]; total: number; } export interface DetectionTaskCreate { query_id: string; platforms: string[]; frequency: string; } export interface DetectionTaskUpdate { platforms?: string[]; frequency?: string; status?: string; } export const detectionApi = { listTasks: (token: string, params?: { skip?: number; limit?: number; status?: string }) => fetchWithAuth(`/api/v1/detection/tasks${buildQuery(params || {})}`, {}, token) as Promise, createTask: (token: string, data: DetectionTaskCreate) => fetchWithAuth("/api/v1/detection/tasks", { method: "POST", body: JSON.stringify(data) }, token) as Promise, updateTask: (token: string, taskId: string, data: DetectionTaskUpdate) => fetchWithAuth(`/api/v1/detection/tasks/${taskId}`, { method: "PUT", body: JSON.stringify(data) }, token) as Promise, deleteTask: (token: string, taskId: string) => fetchWithAuth(`/api/v1/detection/tasks/${taskId}`, { method: "DELETE" }, token) as Promise, triggerTask: (token: string, taskId: string) => fetchWithAuth(`/api/v1/detection/tasks/${taskId}/trigger`, { method: "POST" }, token) as Promise, };