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

/// <summary>
///     Per Phase 7 plan decision #2 — a virtual (calculated) tag that lives in the
///     Equipment tree alongside driver tags. Value is produced by the
///     <see cref="Script"/> referenced by <see cref="ScriptId"/>.
/// </summary>
/// <remarks>
///     <para>
///         <see cref="EquipmentId"/> is mandatory — virtual tags are always scoped to an
///         Equipment node per plan decision #2 (unified Equipment tree, not a separate
///         /Virtual namespace). <see cref="DataType"/> matches the shape used by
///         <c>Tag.DataType</c>.
///     </para>
///     <para>
///         <see cref="ChangeTriggered"/> and <see cref="TimerIntervalMs"/> together realize
///         plan decision #3 (change + timer). At least one must produce evaluations; the
///         Core.VirtualTags engine rejects an all-disabled tag at load time.
///     </para>
/// </remarks>
public sealed class VirtualTag
{
    public Guid VirtualTagRowId { get; set; }
    public long GenerationId { get; set; }

    /// <summary>Stable logical id.</summary>
    public required string VirtualTagId { get; set; }

    /// <summary>Logical FK to <see cref="Equipment.EquipmentId"/> — owner of this virtual tag.</summary>
    public required string EquipmentId { get; set; }

    /// <summary>Browse name — unique within owning Equipment.</summary>
    public required string Name { get; set; }

    /// <summary>DataType string — same vocabulary as <see cref="Tag.DataType"/>.</summary>
    public required string DataType { get; set; }

    /// <summary>Logical FK to <see cref="Script.ScriptId"/> — the script that computes this tag's value.</summary>
    public required string ScriptId { get; set; }

    /// <summary>Re-evaluate when any referenced input tag changes. Default on.</summary>
    public bool ChangeTriggered { get; set; } = true;

    /// <summary>Timer re-evaluation cadence in milliseconds. <c>null</c> = no timer.</summary>
    public int? TimerIntervalMs { get; set; }

    /// <summary>Per plan decision #10 — checkbox to route this tag's values through <c>IHistoryWriter</c>.</summary>
    public bool Historize { get; set; }

    public bool Enabled { get; set; } = true;

    public ConfigGeneration? Generation { get; set; }
}
