using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

namespace StellaOps.Feedser.Exporter.Json;

public sealed class JsonExportResult
{
    public JsonExportResult(
        string exportDirectory,
        DateTimeOffset exportedAt,
        IEnumerable<JsonExportFile> files,
        int advisoryCount,
        long totalBytes)
    {
        if (string.IsNullOrWhiteSpace(exportDirectory))
        {
            throw new ArgumentException("Export directory must be provided.", nameof(exportDirectory));
        }

        ExportDirectory = exportDirectory;
        ExportedAt = exportedAt;
        AdvisoryCount = advisoryCount;
        TotalBytes = totalBytes;

        var list = (files ?? throw new ArgumentNullException(nameof(files)))
            .Where(static file => file is not null)
            .ToImmutableArray();

        Files = list;
        FilePaths = list.Select(static file => file.RelativePath).ToImmutableArray();
    }

    public string ExportDirectory { get; }

    public DateTimeOffset ExportedAt { get; }

    public ImmutableArray<JsonExportFile> Files { get; }

    public ImmutableArray<string> FilePaths { get; }

    public int AdvisoryCount { get; }

    public long TotalBytes { get; }
}
