using System;
using System.Collections.Generic;

namespace StellaOps.Feedser.Storage.Mongo.ChangeHistory;

public sealed class ChangeHistoryRecord
{
    public ChangeHistoryRecord(
        Guid id,
        string sourceName,
        string advisoryKey,
        Guid documentId,
        string documentSha256,
        string currentHash,
        string? previousHash,
        string currentSnapshot,
        string? previousSnapshot,
        IReadOnlyList<ChangeHistoryFieldChange> changes,
        DateTimeOffset capturedAt)
    {
        ArgumentException.ThrowIfNullOrEmpty(sourceName);
        ArgumentException.ThrowIfNullOrEmpty(advisoryKey);
        ArgumentException.ThrowIfNullOrEmpty(documentSha256);
        ArgumentException.ThrowIfNullOrEmpty(currentHash);
        ArgumentException.ThrowIfNullOrEmpty(currentSnapshot);
        ArgumentNullException.ThrowIfNull(changes);

        Id = id;
        SourceName = sourceName;
        AdvisoryKey = advisoryKey;
        DocumentId = documentId;
        DocumentSha256 = documentSha256;
        CurrentHash = currentHash;
        PreviousHash = previousHash;
        CurrentSnapshot = currentSnapshot;
        PreviousSnapshot = previousSnapshot;
        Changes = changes;
        CapturedAt = capturedAt;
    }

    public Guid Id { get; }

    public string SourceName { get; }

    public string AdvisoryKey { get; }

    public Guid DocumentId { get; }

    public string DocumentSha256 { get; }

    public string CurrentHash { get; }

    public string? PreviousHash { get; }

    public string CurrentSnapshot { get; }

    public string? PreviousSnapshot { get; }

    public IReadOnlyList<ChangeHistoryFieldChange> Changes { get; }

    public DateTimeOffset CapturedAt { get; }
}
