import type { LoadSharingSnapshot } from "@lumo/widgets/catalog/ev-charging/load-balancer";
type Allocation = { id: string; label: string; status: "charging" | "idle" | "unavailable";
allocatedWatts: number | null; requestedWatts: number | null; measuredWatts: number | null };
export function adapt(site: string, gridLimitWatts: number | null, buildingWatts: number | null, allocations: Allocation[]): LoadSharingSnapshot {
const kilowatts = (watts: number | null) => watts === null ? null : watts / 1000;
return { site, siteLimitKw: kilowatts(gridLimitWatts), buildingKw: kilowatts(buildingWatts),
chargers: allocations.map(({ id, label, status, allocatedWatts, requestedWatts, measuredWatts }) => ({
id, label, status, allocatedKw: kilowatts(allocatedWatts), requestedKw: kilowatts(requestedWatts), measuredKw: kilowatts(measuredWatts),
})),
};
}