using ZB.MOM.WW.OtOpcUa.Configuration.Enums;

namespace ZB.MOM.WW.OtOpcUa.Configuration.Entities;

/// <summary>
///     Immutable snapshot of a config artifact dispatched to every driver-role node by the
///     ConfigPublishCoordinator. Replaces the v1 <c>ConfigGeneration</c> draft/publish
///     row; the ArtifactBlob carries the SnapshotAndFlatten() output produced by
///     AdminOperationsActor.
/// </summary>
public sealed class Deployment
{
    /// <summary>Gets or sets the unique deployment identifier.</summary>
    public Guid DeploymentId { get; init; } = Guid.NewGuid();

    /// <summary>Gets or sets the revision hash of the deployment artifact.</summary>
    public required string RevisionHash { get; init; }

    /// <summary>Gets or sets the deployment status.</summary>
    public DeploymentStatus Status { get; set; } = DeploymentStatus.Dispatching;

    /// <summary>Gets or sets the name of the user who created the deployment.</summary>
    public required string CreatedBy { get; init; }

    /// <summary>Gets or sets the UTC timestamp when the deployment was created.</summary>
    public DateTime CreatedAtUtc { get; init; } = DateTime.UtcNow;

    /// <summary>Gets or sets the serialized artifact blob containing the configuration.</summary>
    public byte[] ArtifactBlob { get; init; } = Array.Empty<byte>();

    /// <summary>Gets or sets the row version for optimistic concurrency control.</summary>
    public byte[] RowVersion { get; set; } = Array.Empty<byte>();

    /// <summary>Gets or sets the failure reason if the deployment failed.</summary>
    public string? FailureReason { get; set; }

    /// <summary>Gets or sets the UTC timestamp when the deployment was sealed.</summary>
    public DateTime? SealedAtUtc { get; set; }
}
