using ZB.MOM.WW.OtOpcUa.Core.Abstractions;

namespace ZB.MOM.WW.OtOpcUa.Core.ScriptedAlarms;

/// <summary>
///     Operator-authored scripted-alarm configuration. Phase 7 Stream E (config DB schema)
///     materializes these from the <c>ScriptedAlarm</c> + <c>Script</c> tables on publish.
/// </summary>
/// <param name="AlarmId">
///     Stable identity for the alarm — used as the OPC UA ConditionId + the key in the
///     state store. Should be globally unique within the cluster; convention is
///     <c>{EquipmentPath}::{AlarmName}</c>.
/// </param>
/// <param name="EquipmentPath">
///     UNS path of the Equipment node the alarm hangs under. Alarm browse lives here;
///     ACL binding inherits this equipment's scope per Phase 6.2.
/// </param>
/// <param name="AlarmName">Human-readable alarm name — used in the browse tree + Admin UI.</param>
/// <param name="Kind">Concrete OPC UA Part 9 subtype the alarm materializes as.</param>
/// <param name="Severity">Static severity; not currently computed by the predicate.</param>
/// <param name="MessageTemplate">
///     Message text with <c>{TagPath}</c> tokens resolved at event-emission time.
///     Unresolvable tokens emit <c>{?}</c> + a structured
///     error so operators can spot stale references.
/// </param>
/// <param name="PredicateScriptSource">
///     Roslyn C# script returning <c>bool</c>. <c>true</c> = alarm condition currently holds (active);
///     <c>false</c> = condition has cleared. Same sandbox rules as virtual tags.
/// </param>
/// <param name="HistorizeToAveva">
///     When true, every transition emission of this alarm flows to the Historian alarm
///     sink (Stream D). Defaults to true — plant alarm history is usually the
///     operator's primary diagnostic. Galaxy-native alarms default false since Galaxy
///     historises them directly.
/// </param>
/// <param name="Retain">
///     Part 9 retain flag — when true, the condition node remains visible after the
///     predicate clears as long as it has un-acknowledged or un-confirmed transitions.
///     Default true.
/// </param>
public sealed record ScriptedAlarmDefinition(
    string AlarmId,
    string EquipmentPath,
    string AlarmName,
    AlarmKind Kind,
    AlarmSeverity Severity,
    string MessageTemplate,
    string PredicateScriptSource,
    bool HistorizeToAveva = true,
    bool Retain = true);
