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

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

/// <summary>
///     Fleet-wide rollback-safe reservation of ZTag and SAPID. NOT generation-versioned.
///     Exists outside generation flow specifically because old generations and disabled equipment can
///     still hold the same external IDs; per-generation uniqueness indexes fail under rollback/re-enable.
/// </summary>
public sealed class ExternalIdReservation
{
    /// <summary>Gets or sets the unique reservation identifier.</summary>
    public Guid ReservationId { get; set; }

    /// <summary>Gets or sets the kind of reservation (ZTag or SAPID).</summary>
    public required ReservationKind Kind { get; set; }

    /// <summary>Gets or sets the reserved external ID value.</summary>
    public required string Value { get; set; }

    /// <summary>The equipment that owns this reservation. Stays bound even when equipment is disabled.</summary>
    public Guid EquipmentUuid { get; set; }

    /// <summary>First cluster to publish this reservation.</summary>
    public required string ClusterId { get; set; }

    /// <summary>Gets or sets the timestamp when the reservation was first published.</summary>
    public DateTime FirstPublishedAt { get; set; } = DateTime.UtcNow;

    /// <summary>Gets or sets the identifier of the user or system that first published the reservation.</summary>
    public required string FirstPublishedBy { get; set; }

    /// <summary>Gets or sets the timestamp of the most recent publication.</summary>
    public DateTime LastPublishedAt { get; set; } = DateTime.UtcNow;

    /// <summary>Non-null when explicitly released by FleetAdmin (audit-logged, requires reason).</summary>
    public DateTime? ReleasedAt { get; set; }

    /// <summary>Gets or sets the identifier of the user or system that released the reservation.</summary>
    public string? ReleasedBy { get; set; }

    /// <summary>Gets or sets the reason for releasing the reservation.</summary>
    public string? ReleaseReason { get; set; }
}
