import type { CuratedPair, ModelSummary, PredictResult, Sentinel2AOI } from "./types"; // Same-origin in production (FastAPI serves this build); vite dev proxies /api to :7860. const BASE = ""; async function getJSON(path: string): Promise { const res = await fetch(`${BASE}${path}`); if (!res.ok) throw new Error(`${path} -> ${res.status}`); return (await res.json()) as T; } export const api = { models: () => getJSON("/api/models"), curated: () => getJSON("/api/curated"), card: async (modelId: string): Promise => { const res = await fetch(`${BASE}/api/models/${modelId}/card`); if (!res.ok) throw new Error(`card ${modelId} -> ${res.status}`); return res.text(); }, predict: async (pairId: string, modelId: string): Promise => { const res = await fetch(`${BASE}/api/predict`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ pair_id: pairId, model_id: modelId }), }); if (!res.ok) throw new Error(`predict -> ${res.status}`); return (await res.json()) as PredictResult; }, imageUrl: (pairId: string, which: "before" | "after") => `${BASE}/api/curated/${pairId}/${which}.png`, // Sentinel-2 (Track B): baked results only — a plain GET list, no predict call. sentinel2: () => getJSON("/api/sentinel2"), sentinel2ImageUrl: (aoiId: string, which: "before" | "after" | "overlay") => `${BASE}/api/sentinel2/${aoiId}/${which}.png`, };