export interface LegacyConsumerForPlanning { id: string; circuitNumber: string | null; category: string | null; phaseType: string | null; phaseCount: number | null; } export function normalizeCircuitNumber(value: string | null): string | null { if (!value) { return null; } const trimmed = value.trim().toUpperCase(); if (!trimmed) { return null; } if (!/^-\d+F\d+$/.test(trimmed)) { return null; } return trimmed; } export function inferSectionKeyFromLegacyInput(consumer: LegacyConsumerForPlanning): string | null { const category = (consumer.category ?? "").toLowerCase(); if (category.includes("light") || category.includes("beleuchtung")) { return "lighting"; } if (consumer.phaseCount === 3) { return "three_phase"; } if (consumer.phaseCount === 1) { return "single_phase"; } const phaseType = (consumer.phaseType ?? "").toLowerCase(); if (phaseType.includes("three") || phaseType.includes("3")) { return "three_phase"; } if (phaseType.includes("single") || phaseType.includes("1")) { return "single_phase"; } return null; } export function inferSectionKeyFromEquipmentIdentifier(equipmentIdentifier: string): string | null { if (equipmentIdentifier.startsWith("-1F")) { return "lighting"; } if (equipmentIdentifier.startsWith("-2F")) { return "single_phase"; } if (equipmentIdentifier.startsWith("-3F")) { return "three_phase"; } return null; }