const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000"; export interface Scenario { id: string; name: string; status: string; kpis_json: string | null; created_at: string; } export interface ProgressEvent { stage: string; pct: number; } export async function createScenario(name: string): Promise { const res = await fetch(`${API_BASE}/api/scenarios`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name }), }); if (!res.ok) throw new Error(`API error ${res.status}`); return res.json() as Promise; } export async function getScenario(id: string): Promise { const res = await fetch(`${API_BASE}/api/scenarios/${id}`); if (!res.ok) throw new Error(`API error ${res.status}`); return res.json() as Promise; } export async function listScenarios(): Promise { const res = await fetch(`${API_BASE}/api/scenarios`); if (!res.ok) throw new Error(`API error ${res.status}`); return res.json() as Promise; } export function scenarioEventsUrl(id: string): string { return `${API_BASE}/api/scenarios/${id}/events`; }