using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Cleanuparr.Domain.Enums; using Cleanuparr.Domain.Exceptions; using Cleanuparr.Shared.Helpers; namespace Cleanuparr.Persistence.Models.Configuration.General; public sealed record GeneralConfig : IConfig { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } = Guid.NewGuid(); public bool DisplaySupportBanner { get; set; } = true; public bool DryRun { get; set; } public ushort HttpMaxRetries { get; set; } public ushort HttpTimeout { get; set; } = 100; public CertificateValidationType HttpCertificateValidation { get; set; } = CertificateValidationType.Enabled; /// /// Whether outbound requests carry a User-Agent header. /// public bool HttpSendUserAgent { get; set; } public bool StatusCheckEnabled { get; set; } = true; public List IgnoredDownloads { get; set; } = []; public bool ConnectivityCheckEnabled { get; set; } public List ConnectivityCheckUrls { get; set; } = []; public ushort StrikeInactivityWindowHours { get; set; } = 24; /// /// How long archived strike/event history is retained before being pruned, in days. /// public ushort HistoryRetentionDays { get; set; } = 365; public LoggingConfig Log { get; set; } = new(); public AuthConfig Auth { get; set; } = new(); public void Validate() { if (HttpTimeout is 0) { throw new CustomValidationException("HTTP_TIMEOUT must be greater than 0"); } if (StrikeInactivityWindowHours is 0) { throw new CustomValidationException("STRIKE_INACTIVITY_WINDOW_HOURS must be greater than 0"); } if (StrikeInactivityWindowHours > 168) { throw new CustomValidationException("STRIKE_INACTIVITY_WINDOW_HOURS must be less than or equal to 168"); } if (HistoryRetentionDays is 0) { throw new CustomValidationException("HISTORY_RETENTION_DAYS must be greater than 0"); } if (HistoryRetentionDays > 3650) { throw new CustomValidationException("HISTORY_RETENTION_DAYS must be less than or equal to 3650"); } if (ConnectivityCheckEnabled && ConnectivityCheckUrls.Count is 0) { throw new CustomValidationException("At least one connectivity check URL is required when the internet connectivity check is enabled"); } Log.Validate(); Auth.Validate(); } }