using System.Collections.ObjectModel; using OF_DL.Models.Config; namespace OF_DL.Gui.ViewModels; public sealed class ConfigCategoryViewModel : ViewModelBase { public ConfigCategoryViewModel(string categoryName, IEnumerable fields) { CategoryName = categoryName; List fieldList = fields.ToList(); DownloadOnlySpecificDatesField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.DownloadOnlySpecificDates), StringComparison.Ordinal)); DownloadDateSelectionField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.DownloadDateSelection), StringComparison.Ordinal)); CustomDateField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.CustomDate), StringComparison.Ordinal)); LimitDownloadRateField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.LimitDownloadRate), StringComparison.Ordinal)); DownloadLimitInMbPerSecField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.DownloadLimitInMbPerSec), StringComparison.Ordinal)); FolderPerPaidPostField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.FolderPerPaidPost), StringComparison.Ordinal)); FolderPerPostField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.FolderPerPost), StringComparison.Ordinal)); FolderPerPaidMessageField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.FolderPerPaidMessage), StringComparison.Ordinal)); FolderPerMessageField = fieldList.FirstOrDefault(field => string.Equals(field.PropertyName, nameof(Config.FolderPerMessage), StringComparison.Ordinal)); IEnumerable visibleFields = IsDownloadBehavior ? fieldList.Where(field => field.PropertyName is not nameof(Config.DownloadOnlySpecificDates) and not nameof(Config.DownloadDateSelection) and not nameof(Config.CustomDate)) : IsPerformance ? fieldList.Where(field => field.PropertyName is not nameof(Config.LimitDownloadRate) and not nameof(Config.DownloadLimitInMbPerSec)) : IsFolderStructure ? fieldList.Where(field => field.PropertyName is not nameof(Config.FolderPerPaidPost) and not nameof(Config.FolderPerPost) and not nameof(Config.FolderPerPaidMessage) and not nameof(Config.FolderPerMessage)) : fieldList; foreach (ConfigFieldViewModel field in visibleFields) { Fields.Add(field); } } public string CategoryName { get; } public bool IsDownloadBehavior => string.Equals(CategoryName, "Download Behavior", StringComparison.Ordinal); public bool IsPerformance => string.Equals(CategoryName, "Performance", StringComparison.Ordinal); public bool IsFolderStructure => string.Equals(CategoryName, "Folder Structure", StringComparison.Ordinal); public bool IsFileNaming => string.Equals(CategoryName, "File Naming", StringComparison.Ordinal); public ConfigFieldViewModel? DownloadOnlySpecificDatesField { get; } public ConfigFieldViewModel? DownloadDateSelectionField { get; } public ConfigFieldViewModel? CustomDateField { get; } public ConfigFieldViewModel? LimitDownloadRateField { get; } public ConfigFieldViewModel? DownloadLimitInMbPerSecField { get; } public ConfigFieldViewModel? FolderPerPaidPostField { get; } public ConfigFieldViewModel? FolderPerPostField { get; } public ConfigFieldViewModel? FolderPerPaidMessageField { get; } public ConfigFieldViewModel? FolderPerMessageField { get; } public bool HasSpecificDateFilterFields => DownloadOnlySpecificDatesField != null && DownloadDateSelectionField != null && CustomDateField != null; public bool HasRateLimitFields => LimitDownloadRateField != null && DownloadLimitInMbPerSecField != null; public bool HasFolderStructureFields => FolderPerPaidPostField != null && FolderPerPostField != null && FolderPerPaidMessageField != null && FolderPerMessageField != null; public string SpecificDateFilterHelpText { get { List parts = []; if (!string.IsNullOrWhiteSpace(DownloadOnlySpecificDatesField?.HelpText)) { parts.Add(DownloadOnlySpecificDatesField.HelpText); } if (!string.IsNullOrWhiteSpace(DownloadDateSelectionField?.HelpText)) { parts.Add(DownloadDateSelectionField.HelpText); } if (!string.IsNullOrWhiteSpace(CustomDateField?.HelpText)) { parts.Add(CustomDateField.HelpText); } return string.Join(" ", parts.Distinct(StringComparer.Ordinal)); } } public string RateLimitHelpText { get { List parts = []; if (!string.IsNullOrWhiteSpace(LimitDownloadRateField?.HelpText)) { parts.Add(LimitDownloadRateField.HelpText); } if (!string.IsNullOrWhiteSpace(DownloadLimitInMbPerSecField?.HelpText)) { parts.Add(DownloadLimitInMbPerSecField.HelpText); } return string.Join(" ", parts.Distinct(StringComparer.Ordinal)); } } public string FolderStructureHelpText { get { List parts = []; if (!string.IsNullOrWhiteSpace(FolderPerPaidPostField?.HelpText)) { parts.Add(FolderPerPaidPostField.HelpText); } if (!string.IsNullOrWhiteSpace(FolderPerPostField?.HelpText)) { parts.Add(FolderPerPostField.HelpText); } if (!string.IsNullOrWhiteSpace(FolderPerPaidMessageField?.HelpText)) { parts.Add(FolderPerPaidMessageField.HelpText); } if (!string.IsNullOrWhiteSpace(FolderPerMessageField?.HelpText)) { parts.Add(FolderPerMessageField.HelpText); } return string.Join(" ", parts.Distinct(StringComparer.Ordinal)); } } public bool HasSpecificDateFilterHelpText => !string.IsNullOrWhiteSpace(SpecificDateFilterHelpText); public bool HasRateLimitHelpText => !string.IsNullOrWhiteSpace(RateLimitHelpText); public bool HasFolderStructureHelpText => !string.IsNullOrWhiteSpace(FolderStructureHelpText); public ObservableCollection Fields { get; } = []; }