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

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

/// <summary>
///     Per-(node, deployment) apply progress row owned by the DriverHostActor. Replaces the
///     v1 <c>ClusterNodeGenerationState</c> single-row-per-node model with a history
///     of every apply attempt so the ConfigPublishCoordinator can reconstruct in-flight state
///     after a failover.
/// </summary>
public sealed class NodeDeploymentState
{
    /// <summary>Gets or sets the cluster node identifier.</summary>
    public required string NodeId { get; init; }

    /// <summary>Gets or sets the deployment identifier.</summary>
    public Guid DeploymentId { get; init; }

    /// <summary>Gets or sets the deployment status on this node.</summary>
    public NodeDeploymentStatus Status { get; set; } = NodeDeploymentStatus.Applying;

    /// <summary>Gets or sets the UTC timestamp when the deployment application started.</summary>
    public DateTime StartedAtUtc { get; set; } = DateTime.UtcNow;

    /// <summary>Gets or sets the UTC timestamp when the deployment was successfully applied, or null if not yet applied.</summary>
    public DateTime? AppliedAtUtc { get; set; }

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

    /// <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 cluster node entity reference.</summary>
    public ClusterNode? Node { get; set; }
    /// <summary>Gets or sets the deployment entity reference.</summary>
    public Deployment? Deployment { get; set; }
}
