using Common.Enums; using Microsoft.Extensions.Configuration; namespace Common.Configuration.DownloadClient; /// /// Configuration for a specific download client /// public sealed record ClientConfig { /// /// Unique identifier for this client /// public string Id { get; init; } = Guid.NewGuid().ToString("N"); /// /// Friendly name for this client /// public string Name { get; init; } = string.Empty; /// /// Type of download client /// public DownloadClientType Type { get; init; } = DownloadClientType.None; /// /// Host address for the download client /// public string Host { get; init; } = string.Empty; /// /// Username for authentication /// public string Username { get; init; } = string.Empty; /// /// Password for authentication /// public string Password { get; init; } = string.Empty; /// /// Default category to use /// public string Category { get; init; } = string.Empty; /// /// Path to download directory /// public string Path { get; init; } = string.Empty; /// /// Whether this client is enabled /// public bool Enabled { get; init; } = true; /// /// The base URL path component, used by clients like Transmission and Deluge /// [ConfigurationKeyName("URL_BASE")] public string UrlBase { get; init; } = string.Empty; /// /// Use HTTPS protocol /// public bool UseHttps { get; init; } = false; /// /// The computed full URL for the client /// public Uri Url => new($"{Host.TrimEnd('/')}/{UrlBase.TrimStart('/').TrimEnd('/')}"); /// /// Validates the configuration /// public void Validate() { if (string.IsNullOrWhiteSpace(Id)) { throw new InvalidOperationException("Client ID cannot be empty"); } if (string.IsNullOrWhiteSpace(Name)) { throw new InvalidOperationException($"Client name cannot be empty for client ID: {Id}"); } if (string.IsNullOrWhiteSpace(Host)) { throw new InvalidOperationException($"Host cannot be empty for client ID: {Id}"); } if (Type == DownloadClientType.None) { throw new InvalidOperationException($"Client type must be specified for client ID: {Id}"); } } }