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

/// <summary>
///     v3 UNS projection row: a reference from an <see cref="Equipment"/> to an existing raw
///     <see cref="Tag"/>. UNS authoring is reference-only — equipment no longer authors
///     <c>TagConfig</c> or binds a driver; it points at raw tags (optionally under a display-name
///     override). The backing raw tag is the single value source; the UNS node fans out from it.
/// </summary>
public sealed class UnsTagReference
{
    /// <summary>Gets or sets the database row identifier (PK).</summary>
    public Guid UnsTagReferenceRowId { get; set; }

    /// <summary>Stable logical ID, unique fleet-wide.</summary>
    public required string UnsTagReferenceId { get; set; }

    /// <summary>Logical FK to <see cref="Equipment.EquipmentId"/> — the referencing equipment.</summary>
    public required string EquipmentId { get; set; }

    /// <summary>Logical FK to <see cref="Tag.TagId"/> — the backing raw tag (same cluster as the equipment).</summary>
    public required string TagId { get; set; }

    /// <summary>
    ///     Optional UNS display-name override; <see langword="null"/> = use the raw tag's <c>Name</c>.
    ///     The effective name must be unique within the equipment across references, VirtualTags, and
    ///     ScriptedAlarms (enforced at authoring and at the deploy gate).
    /// </summary>
    public string? DisplayNameOverride { get; set; }

    /// <summary>Sibling display ordering within the equipment's Tags list.</summary>
    public int SortOrder { get; set; }

    /// <summary>Optimistic concurrency token for last-write-wins detection in the v2 live-edit model.</summary>
    public byte[] RowVersion { get; set; } = Array.Empty<byte>();
}
