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

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

/// <summary>
///     Fleet-wide rollback-safe reservation of ZTag and SAPID. Per decision #124 — 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
{
    public Guid ReservationId { get; set; }

    public required ReservationKind Kind { get; set; }

    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; }

    public DateTime FirstPublishedAt { get; set; } = DateTime.UtcNow;

    public required string FirstPublishedBy { get; set; }

    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; }

    public string? ReleasedBy { get; set; }

    public string? ReleaseReason { get; set; }
}
