using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using StellaOps.Concelier.Models; namespace StellaOps.Concelier.Exporter.Json; public sealed class JsonExportResult { public JsonExportResult( string exportDirectory, DateTimeOffset exportedAt, IEnumerable files, int advisoryCount, long totalBytes, IEnumerable? advisories = null) { if (string.IsNullOrWhiteSpace(exportDirectory)) { throw new ArgumentException("Export directory must be provided.", nameof(exportDirectory)); } var list = (files ?? throw new ArgumentNullException(nameof(files))) .Where(static file => file is not null) .ToImmutableArray(); var advisoryList = (advisories ?? Array.Empty()) .Where(static advisory => advisory is not null) .ToImmutableArray(); ExportDirectory = exportDirectory; ExportedAt = exportedAt; TotalBytes = totalBytes; Files = list; FilePaths = list.Select(static file => file.RelativePath).ToImmutableArray(); Advisories = advisoryList; AdvisoryCount = advisoryList.IsDefaultOrEmpty ? advisoryCount : advisoryList.Length; } public string ExportDirectory { get; } public DateTimeOffset ExportedAt { get; } public ImmutableArray Files { get; } public ImmutableArray FilePaths { get; } public ImmutableArray Advisories { get; } public int AdvisoryCount { get; } public long TotalBytes { get; } }