using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace StellaOps.Cryptography; public sealed class CryptoRegistryProfiles { public IReadOnlyList PreferredProviders { get; } public string ActiveProfile { get; } public IReadOnlyDictionary> Profiles { get; } public CryptoRegistryProfiles( IEnumerable preferredProviders, string activeProfile, IDictionary> profiles) { PreferredProviders = (preferredProviders ?? throw new ArgumentNullException(nameof(preferredProviders))) .Where(p => !string.IsNullOrWhiteSpace(p)) .Select(p => p.Trim()) .ToArray(); ActiveProfile = string.IsNullOrWhiteSpace(activeProfile) ? throw new ArgumentException("Active profile is required", nameof(activeProfile)) : activeProfile.Trim(); Profiles = new ReadOnlyDictionary>(profiles ?? throw new ArgumentNullException(nameof(profiles))); } public IReadOnlyList ResolvePreferredOrder(string? profileName = null) { if (!string.IsNullOrWhiteSpace(profileName) && Profiles.TryGetValue(profileName!, out var specific)) { return specific; } if (Profiles.TryGetValue(ActiveProfile, out var active)) { return active; } return PreferredProviders; } }