using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; namespace StellaOps.AdvisoryAI.Tools; /// /// Summarises dependency graph characteristics used by deterministic tooling. /// public sealed class DependencyAnalysisResult { private DependencyAnalysisResult( string artifactId, ImmutableArray nodes, ImmutableDictionary metadata) { ArtifactId = artifactId; Nodes = nodes; Metadata = metadata; } public string ArtifactId { get; } public ImmutableArray Nodes { get; } public ImmutableDictionary Metadata { get; } public static DependencyAnalysisResult Create( string artifactId, IEnumerable nodes, IReadOnlyDictionary metadata) { ArgumentException.ThrowIfNullOrWhiteSpace(artifactId); ArgumentNullException.ThrowIfNull(nodes); ArgumentNullException.ThrowIfNull(metadata); return new DependencyAnalysisResult( artifactId.Trim(), nodes.ToImmutableArray(), metadata.ToImmutableDictionary(StringComparer.Ordinal)); } public static DependencyAnalysisResult Empty(string artifactId) => new DependencyAnalysisResult( artifactId?.Trim() ?? string.Empty, ImmutableArray.Empty, ImmutableDictionary.Empty); } public sealed class DependencyNodeSummary { public DependencyNodeSummary( string identifier, IReadOnlyList versions, int runtimeOccurrences, int developmentOccurrences) { ArgumentException.ThrowIfNullOrWhiteSpace(identifier); Identifier = identifier.Trim(); Versions = versions?.ToImmutableArray() ?? ImmutableArray.Empty; RuntimeOccurrences = Math.Max(runtimeOccurrences, 0); DevelopmentOccurrences = Math.Max(developmentOccurrences, 0); } public string Identifier { get; } public ImmutableArray Versions { get; } public int RuntimeOccurrences { get; } public int DevelopmentOccurrences { get; } } internal sealed class NodeAccumulator { public string Identifier { get; set; } = string.Empty; public HashSet Versions { get; set; } = new(StringComparer.Ordinal); public int RuntimeOccurrences { get; set; } public int DevelopmentOccurrences { get; set; } }