using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;

namespace ZB.MOM.WW.ScadaBridge.Commons.Entities.Deployment;

public class DeploymentRecord
{
    /// <summary>
    /// The deployment record identifier.
    /// </summary>
    public int Id { get; set; }

    /// <summary>
    /// The instance identifier being deployed.
    /// </summary>
    public int InstanceId { get; set; }

    /// <summary>
    /// The current deployment status.
    /// </summary>
    public DeploymentStatus Status { get; set; }

    /// <summary>
    /// The deployment identifier.
    /// </summary>
    public string DeploymentId { get; set; }

    /// <summary>
    /// The revision hash of the deployed configuration, or null.
    /// </summary>
    public string? RevisionHash { get; set; }

    /// <summary>
    /// The user who initiated the deployment.
    /// </summary>
    public string DeployedBy { get; set; }

    /// <summary>
    /// The time when the deployment was initiated.
    /// </summary>
    public DateTimeOffset DeployedAt { get; set; }

    /// <summary>
    /// The time when the deployment completed, or null if still in progress.
    /// </summary>
    public DateTimeOffset? CompletedAt { get; set; }

    /// <summary>
    /// Error message if the deployment failed, or null.
    /// </summary>
    public string? ErrorMessage { get; set; }

    /// <summary>
    /// Optimistic concurrency token for deployment status updates.
    /// </summary>
    public byte[] RowVersion { get; set; } = [];

    /// <summary>
    /// Initializes a new instance of the DeploymentRecord.
    /// </summary>
    /// <param name="deploymentId">The deployment identifier.</param>
    /// <param name="deployedBy">The user initiating the deployment.</param>
    public DeploymentRecord(string deploymentId, string deployedBy)
    {
        DeploymentId = deploymentId ?? throw new ArgumentNullException(nameof(deploymentId));
        DeployedBy = deployedBy ?? throw new ArgumentNullException(nameof(deployedBy));
    }
}
