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

/// <summary>
/// Stores the deployed configuration snapshot for an instance.
/// Captured at deploy time; compared against template-derived (live flattened) config for staleness detection.
/// </summary>
public class DeployedConfigSnapshot
{
    /// <summary>Primary key.</summary>
    public int Id { get; set; }
    /// <summary>Foreign key to the owning <c>Instance</c> entity.</summary>
    public int InstanceId { get; set; }
    /// <summary>Unique deployment identifier assigned at deploy time for idempotency.</summary>
    public string DeploymentId { get; set; }
    /// <summary>Revision hash of the flattened configuration at deploy time, used for staleness detection.</summary>
    public string RevisionHash { get; set; }

    /// <summary>
    /// JSON-serialized FlattenedConfiguration captured at deploy time.
    /// </summary>
    public string ConfigurationJson { get; set; }

    /// <summary>UTC timestamp when this snapshot was persisted.</summary>
    public DateTimeOffset DeployedAt { get; set; }

    /// <summary>Initializes a new snapshot with the deployment identity, revision hash, and serialized configuration.</summary>
    /// <param name="deploymentId">Unique deployment identifier.</param>
    /// <param name="revisionHash">Revision hash of the flattened configuration.</param>
    /// <param name="configurationJson">JSON-serialized flattened configuration.</param>
    public DeployedConfigSnapshot(string deploymentId, string revisionHash, string configurationJson)
    {
        DeploymentId = deploymentId ?? throw new ArgumentNullException(nameof(deploymentId));
        RevisionHash = revisionHash ?? throw new ArgumentNullException(nameof(revisionHash));
        ConfigurationJson = configurationJson ?? throw new ArgumentNullException(nameof(configurationJson));
    }
}
