using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Streaming;
public record AlarmStateChanged(
string InstanceUniqueName,
string AlarmName,
AlarmState State,
int Priority,
DateTimeOffset Timestamp) : ISiteStreamEvent
{
///
/// Severity level when is .
/// Always for binary trigger types
/// (ValueMatch, RangeViolation, RateOfChange); set by the HiLo trigger
/// type to one of Low/LowLow/High/HighHigh based on the crossed setpoint.
/// Added as an init-property so existing positional constructors still
/// work โ message contract evolves additively.
///
public AlarmLevel Level { get; init; } = AlarmLevel.None;
///
/// Optional per-band operator message (e.g., "Coolant critically low โ
/// shut down"). Set by HiLo triggers when the per-setpoint message is
/// configured; otherwise empty. Notification routing and UI tooltips may
/// surface this to operators.
///
public string Message { get; init; } = string.Empty;
///
/// Whether this alarm is computed at the site or mirrored from a native
/// source. Defaults to .
///
public AlarmKind Kind { get; init; } = AlarmKind.Computed;
private AlarmConditionState? _condition;
///
/// Unified A&C-style condition (active/acked/shelved/suppressed + severity).
/// When not explicitly set, defaults to a computed mapping of
/// + so existing callers and
/// computed alarms carry a correct condition without extra work.
///
public AlarmConditionState Condition
{
get => _condition ?? AlarmConditionStateFactory.ForComputed(State, Priority);
init => _condition = value;
}
/// Native per-condition key (e.g. "Tank01.Level.HiHi"); empty for computed alarms.
public string SourceReference { get; init; } = string.Empty;
/// Native alarm type name (e.g. "AnalogLimitAlarm.HiHi"); empty for computed alarms.
public string AlarmTypeName { get; init; } = string.Empty;
/// Native alarm category/taxonomy; empty for computed alarms.
public string Category { get; init; } = string.Empty;
/// Operator who acknowledged at the source (display-only); empty otherwise.
public string OperatorUser { get; init; } = string.Empty;
/// Operator comment captured at the source (display-only); empty otherwise.
public string OperatorComment { get; init; } = string.Empty;
/// When the native condition originally became active, if known.
public DateTimeOffset? OriginalRaiseTime { get; init; }
///
/// When the condition was acknowledged, or null while it is unacknowledged.
/// Additive native-mirror enrichment (MES alarm-status API ยง6.4) โ the ack timestamp
/// the MES AlarmInfo.AckDT field reports and the Alarms.CurrentAsync()
/// script accessor surfaces as ScriptAlarm.AckTime.
///
///
/// Provenance: the DCL stamps the SOURCE's own ack instant where the protocol supplies
/// one (OPC UA A&C exposes AckedState/TransitionTime); where it does not
/// (MxAccess Gateway alarm events), the DCL stamps the transition time it OBSERVED the
/// ack at. It is therefore never fabricated, but for MxGateway sources it is accurate
/// to "when the system saw the ack", not necessarily to the operator's click.
///
///
///
/// Null for computed alarms (they are auto-acked and have no operator ack event) and
/// null while a native condition is unacknowledged; cleared on re-raise, because a
/// re-raise transition carries Acknowledged = false.
///
///
public DateTimeOffset? AckTime { get; init; }
/// Current source value (display-only); empty for computed alarms.
public string CurrentValue { get; init; } = string.Empty;
/// Limit/threshold value for native limit alarms (display-only); empty otherwise.
public string LimitValue { get; init; } = string.Empty;
///
/// Canonical name of the native alarm SOURCE BINDING this condition belongs to
/// (e.g. "Motor1.MotorAlarms"). Lets the Debug View nest live native conditions
/// under their configured binding node. Empty for computed alarms. Additive.
///
public string NativeSourceCanonicalName { get; init; } = string.Empty;
///
/// True when this row is a placeholder emitted for a CONFIGURED native source
/// binding that currently has no active conditions, so the Debug View tree can
/// show the binding node as "no active conditions". Additive; default false.
///
public bool IsConfiguredPlaceholder { get; init; }
}