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

public class AuditLogEntry
{
    /// <summary>Auto-incremented primary key.</summary>
    public int Id { get; set; }
    /// <summary>Username of the actor who performed the action.</summary>
    public string User { get; set; }
    /// <summary>Action performed (e.g. Created, Updated, Deleted).</summary>
    public string Action { get; set; }
    /// <summary>Entity type name (e.g. Template, ExternalSystem).</summary>
    public string EntityType { get; set; }
    /// <summary>String representation of the entity's primary key.</summary>
    public string EntityId { get; set; }
    /// <summary>Human-readable name of the affected entity.</summary>
    public string EntityName { get; set; }
    /// <summary>JSON snapshot of the entity's state after the action; null for deletes.</summary>
    public string? AfterStateJson { get; set; }
    /// <summary>UTC timestamp when the audit entry was recorded.</summary>
    public DateTimeOffset Timestamp { get; set; }
    /// <summary>Bundle import session id when this entry was created during a bundle import; otherwise null.</summary>
    public Guid? BundleImportId { get; set; }

    /// <summary>
    /// Creates an audit log entry for the specified user action on a named entity.
    /// </summary>
    /// <param name="user">Username of the actor performing the action.</param>
    /// <param name="action">Action name (e.g. Created, Updated, Deleted).</param>
    /// <param name="entityType">Entity type name.</param>
    /// <param name="entityId">String primary key of the affected entity.</param>
    /// <param name="entityName">Human-readable name of the affected entity.</param>
    public AuditLogEntry(string user, string action, string entityType, string entityId, string entityName)
    {
        User = user ?? throw new ArgumentNullException(nameof(user));
        Action = action ?? throw new ArgumentNullException(nameof(action));
        EntityType = entityType ?? throw new ArgumentNullException(nameof(entityType));
        EntityId = entityId ?? throw new ArgumentNullException(nameof(entityId));
        EntityName = entityName ?? throw new ArgumentNullException(nameof(entityName));
    }
}
