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 duplicateIds = Clients .GroupBy(c => c.Id) .Where(g => g.Count() > 1) .Select(g => g.Key) .ToList(); if (duplicateIds.Any()) { throw new InvalidOperationException($"Duplicate client IDs found: {string.Join(", ", duplicateIds)}"); } // Validate each client configuration foreach (var client in Clients) { if (client.Id == Guid.Empty) { throw new InvalidOperationException("Client ID cannot be empty"); } if (string.IsNullOrWhiteSpace(client.Name)) { throw new InvalidOperationException($"Client name cannot be empty for client ID: {client.Id}"); } if (string.IsNullOrWhiteSpace(client.Host)) { throw new InvalidOperationException($"Host cannot be empty for client ID: {client.Id}"); } } } }