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

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

/// <summary>
///     One canonical tag (signal) in a cluster's generation. Per decision #110:
///     <see cref="EquipmentId"/> is REQUIRED when the driver is in an Equipment-kind namespace
///     and NULL when in SystemPlatform-kind namespace (Galaxy hierarchy preserved).
/// </summary>
public sealed class Tag
{
    public Guid TagRowId { get; set; }

    public long GenerationId { get; set; }

    public required string TagId { get; set; }

    public required string DriverInstanceId { get; set; }

    public string? DeviceId { get; set; }

    /// <summary>
    ///     Required when driver is in Equipment-kind namespace; NULL when in SystemPlatform-kind.
    ///     Cross-table invariant enforced by sp_ValidateDraft (decision #110).
    /// </summary>
    public string? EquipmentId { get; set; }

    public required string Name { get; set; }

    /// <summary>Only used when <see cref="EquipmentId"/> is NULL (SystemPlatform namespace).</summary>
    public string? FolderPath { get; set; }

    /// <summary>OPC UA built-in type name (Boolean / Int32 / Float / etc.).</summary>
    public required string DataType { get; set; }

    public required TagAccessLevel AccessLevel { get; set; }

    /// <summary>Per decisions #44–45 — opt-in for write retry eligibility.</summary>
    public bool WriteIdempotent { get; set; }

    public string? PollGroupId { get; set; }

    /// <summary>Register address / scaling / poll group / byte-order / etc. — schemaless per driver type.</summary>
    public required string TagConfig { get; set; }

    public ConfigGeneration? Generation { get; set; }
}
