// Thin, self-contained fetch client for the cable-sizing module. Deliberately // not merged into ../utils/api.ts to keep this module's frontend footprint a // single new file rather than growing the existing shared API file - see // docs/cable-sizing-module.md. import type { CableSizingAlert, CableSizingInput, CableSizingResult, InsulationMaterial, LayingMethod, } from "../../cable-sizing/domain/cable-sizing-calculation"; async function request(url: string, init?: RequestInit): Promise { const response = await fetch(url, { ...init, headers: { "Content-Type": "application/json", ...init?.headers }, cache: "no-store", }); if (!response.ok) { let details = await response.text(); try { const parsed = JSON.parse(details) as { error?: unknown }; if (typeof parsed.error === "string") details = parsed.error; } catch { // keep raw text } throw new Error(details || `Anfrage fehlgeschlagen (Status ${response.status})`); } return response.json() as Promise; } export interface CalculateCableSizingResponse { calculationId: string; result: CableSizingResult; alerts: CableSizingAlert[]; } export function calculateCableSizing( input: CableSizingInput, context?: { projectId?: string; circuitId?: string; equipmentIdentifier?: string } ): Promise { return request("/api/cable-sizing/calculate", { method: "POST", body: JSON.stringify({ ...input, context }), }); } export function markCableSizingCalculationApplied(calculationId: string): Promise { return request(`/api/cable-sizing/calculations/${calculationId}/applied`, { method: "POST", }); } export interface LayingMethodOption { method: LayingMethod; label: string; dataVerified: boolean; } export function listLayingMethods(): Promise { return request("/api/cable-sizing/laying-methods"); } export interface InsulationMaterialOption { insulation: InsulationMaterial; label: string; } export function listInsulationMaterials(): Promise { return request("/api/cable-sizing/insulation-materials"); }