using Common.Exceptions; namespace Common.Configuration.DownloadClient; public sealed record DownloadClientConfig : IConfig { /// /// Collection of download clients configured for the application /// public List Clients { get; init; } = new(); /// /// Gets a client configuration by id /// /// The client id /// The client configuration or null if not found public ClientConfig? GetClientConfig(Guid id) { return Clients.FirstOrDefault(c => c.Id == id); } /// /// Gets all enabled clients /// /// Collection of enabled client configurations public IEnumerable GetEnabledClients() { return Clients.Where(c => c.Enabled); } /// /// Validates the configuration to ensure it meets requirements /// public void Validate() { // Validate clients have unique IDs var duplicateNames = Clients .GroupBy(c => c.Name) .Where(g => g.Count() > 1) .Select(g => g.Key) .ToList(); if (duplicateNames.Any()) { throw new ValidationException($"Duplicate client names found: {string.Join(", ", duplicateNames)}"); } // Validate each client configuration foreach (var client in Clients) { client.Validate(); } } }