using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace StellaOps.Cryptography.DependencyInjection; /// /// Options controlling crypto provider registry ordering and selection. /// public sealed class CryptoProviderRegistryOptions { private readonly Dictionary profiles = new(StringComparer.OrdinalIgnoreCase); /// /// Ordered list of preferred provider names. Providers appearing here are consulted first. /// public IList PreferredProviders { get; } = new List(); /// /// Optional active profile name (e.g. "ru-offline") that overrides . /// public string? ActiveProfile { get; set; } /// /// Regional or environment-specific provider preference profiles. /// public IDictionary Profiles => profiles; public IReadOnlyList ResolvePreferredProviders() { static IReadOnlyList Normalise(IEnumerable items) => new ReadOnlyCollection( items.Where(static value => !string.IsNullOrWhiteSpace(value)) .Select(static value => value.Trim()) .ToArray()); if (!string.IsNullOrWhiteSpace(ActiveProfile) && profiles.TryGetValue(ActiveProfile, out var profile) && profile.PreferredProviders.Count > 0) { return Normalise(profile.PreferredProviders); } if (PreferredProviders.Count > 0) { return Normalise(PreferredProviders); } return Array.Empty(); } } public sealed class CryptoProviderProfileOptions { /// /// Ordered list of preferred provider names for the profile. /// public IList PreferredProviders { get; } = new List(); }