using SSPCTester.Devices.Interfaces; namespace SSPCTester.Devices.Config; public static class DaqChannelOptionsNormalizer { public const int ChannelSlots = 8; public static List Normalize(IEnumerable? channels) { var byPhysicalChannel = (channels ?? Enumerable.Empty()) .Where(x => x.PhysicalChannel is >= 0 and < ChannelSlots) .GroupBy(x => x.PhysicalChannel) .ToDictionary(x => x.Key, x => x.First()); var normalized = new List(ChannelSlots); for (int physicalChannel = 0; physicalChannel < ChannelSlots; physicalChannel++) { byPhysicalChannel.TryGetValue(physicalChannel, out var source); normalized.Add(new DaqChannelOptions { PhysicalChannel = physicalChannel, Role = NormalizeRole(source?.Role), Name = string.IsNullOrWhiteSpace(source?.Name) ? $"CH{physicalChannel}" : source.Name, Scale = source?.Scale ?? 1, Offset = source?.Offset ?? 0, IsCalibrated = source?.IsCalibrated ?? false }); } return normalized; } public static string NormalizeRole(string? role) => Enum.TryParse(role, ignoreCase: true, out var parsed) ? parsed.ToString() : nameof(DaqChannelRole.Unconfigured); }