using System; using System.Collections.Immutable; using System.Text.Json.Serialization; using StellaOps.Scanner.Core.Contracts; namespace StellaOps.Scanner.Diff; public enum ComponentChangeKind { Added, Removed, VersionChanged, MetadataChanged, } public sealed record ComponentDiffRequest { public required ComponentGraph OldGraph { get; init; } public required ComponentGraph NewGraph { get; init; } public SbomView View { get; init; } = SbomView.Inventory; public required DateTimeOffset GeneratedAt { get; init; } public string? OldImageDigest { get; init; } = null; public string? NewImageDigest { get; init; } = null; } public sealed record ComponentChange { [JsonPropertyName("kind")] public ComponentChangeKind Kind { get; init; } [JsonPropertyName("componentKey")] public string ComponentKey { get; init; } = string.Empty; [JsonPropertyName("introducingLayer")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? IntroducingLayer { get; init; } = null; [JsonPropertyName("removingLayer")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? RemovingLayer { get; init; } = null; [JsonPropertyName("oldComponent")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public AggregatedComponent? OldComponent { get; init; } = null; [JsonPropertyName("newComponent")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public AggregatedComponent? NewComponent { get; init; } = null; } public sealed record LayerDiff { [JsonPropertyName("layerDigest")] public string LayerDigest { get; init; } = string.Empty; [JsonPropertyName("changes")] public ImmutableArray Changes { get; init; } = ImmutableArray.Empty; } public sealed record DiffSummary { [JsonPropertyName("added")] public int Added { get; init; } [JsonPropertyName("removed")] public int Removed { get; init; } [JsonPropertyName("versionChanged")] public int VersionChanged { get; init; } [JsonPropertyName("metadataChanged")] public int MetadataChanged { get; init; } } public sealed record ComponentDiffDocument { [JsonPropertyName("generatedAt")] public DateTimeOffset GeneratedAt { get; init; } [JsonPropertyName("view")] public SbomView View { get; init; } [JsonPropertyName("oldImageDigest")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? OldImageDigest { get; init; } = null; [JsonPropertyName("newImageDigest")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? NewImageDigest { get; init; } = null; [JsonPropertyName("summary")] public DiffSummary Summary { get; init; } = new(); [JsonPropertyName("layers")] public ImmutableArray Layers { get; init; } = ImmutableArray.Empty; }