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

/// <summary>
///     User-authored C# script source, referenced by
///     <see cref="VirtualTag"/> and <see cref="ScriptedAlarm"/>. One row per script,
///     per generation. <c>SourceHash</c> is the compile-cache key.
/// </summary>
/// <remarks>
///     <para>
///         Scripts are generation-scoped: a draft's edit creates a new row in the draft
///         generation, the old row stays frozen in the published generation. Shape mirrors
///         the other generation-scoped entities (Equipment, Tag, etc.) — <c>ScriptId</c> is
///         the stable logical id that carries across generations; <c>ScriptRowId</c> is the
///         row identity.
///     </para>
/// </remarks>
public sealed class Script
{
    /// <summary>Gets or sets the script row identifier.</summary>
    public Guid ScriptRowId { get; set; }

    /// <summary>Stable logical id. Globally unique in v2.</summary>
    public required string ScriptId { get; set; }

    /// <summary>Operator-friendly name for log filtering + Admin UI list view.</summary>
    public required string Name { get; set; }

    /// <summary>Raw C# source. Size bounded by the DB column (nvarchar(max)).</summary>
    public required string SourceCode { get; set; }

    /// <summary>SHA-256 of <see cref="SourceCode"/> — compile-cache key for Phase 7 Stream A's <c>CompiledScriptCache</c>.</summary>
    public required string SourceHash { get; set; }

    /// <summary>Language — always "CSharp" today; placeholder for future engines (Python/Lua).</summary>
    public string Language { get; set; } = "CSharp";

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