using Akka.Actor;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.Extensions.Logging;
using ZB.MOM.WW.ScadaBridge.Commons.Types;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Scripts;
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Actors;
///
/// Alarm Execution Actor -- short-lived child of Alarm Actor.
/// Same pattern as ScriptExecutionActor.
/// CAN call Instance.CallScript() (ask to sibling Script Actor).
/// Instance scripts CANNOT call alarm on-trigger scripts (no API for it).
/// Supervision: Stop on unhandled exception.
///
public class AlarmExecutionActor : ReceiveActor
{
/// Initializes a new and immediately schedules execution of the alarm on-trigger script.
/// The canonical name of the alarm that triggered.
/// The name of the owning instance.
/// The alarm severity level at the time of triggering.
/// The alarm priority value.
/// The alarm message to pass to the script.
/// The pre-compiled on-trigger script to execute.
/// Reference to the parent instance actor for attribute/script calls.
/// Shared script library providing common utilities.
/// Site runtime configuration options, including the execution timeout.
/// Logger for execution diagnostics.
/// The on-trigger script's per-script execution timeout in seconds. Null or non-positive falls back to the global .
///
/// ParentExecutionId tag-cascade: the execution id of
/// the context that fired this alarm, threaded into the on-trigger script's
/// as its ParentExecutionId so the
/// alarm-triggered run chains under its firing context. Null today (no
/// Guid-typed firing id exists yet) — the run is a root, but the plumbing
/// is in place for a future firing id.
///
public AlarmExecutionActor(
string alarmName,
string instanceName,
AlarmLevel level,
int priority,
string message,
Script