namespace SeaHaven.Services.Helpers { /// /// Fixed board flag palette (must match FE FLAG_COLORS). Values stored as canonical #RRGGBB. /// public static class WorkOrderFlagColors { public static readonly HashSet Allowed = new(StringComparer.OrdinalIgnoreCase) { "#EF4444", "#F97316", "#F59E0B", "#EAB308", "#22C55E", "#14B8A6", "#3B82F6", "#8B5CF6" }; /// /// Normalizes to # + 6 uppercase hex digits, or null if empty. /// Returns false if the value is non-empty but not a valid hex color. /// public static bool TryNormalize(string? value, out string? canonical) { canonical = null; if (string.IsNullOrWhiteSpace(value)) return true; var trimmed = value.Trim(); if (trimmed.Length == 6 && trimmed[0] != '#') trimmed = "#" + trimmed; if (trimmed.Length != 7 || trimmed[0] != '#') return false; for (var i = 1; i < 7; i++) { if (!Char.IsAsciiHexDigit(trimmed[i])) return false; } canonical = "#" + trimmed[1..].ToUpperInvariant(); return true; } public static bool IsAllowed(string? canonical) => canonical != null && Allowed.Contains(canonical); } }