using System.Text.Json;
using ZB.MOM.WW.Audit;
namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
///
/// Flow Debugger Live run of an inbound API method (design 2026-09-05 §7.1): executes the
/// method script on the ACTIVE central node with as the request
/// body, tracing every routed site run, and returns the whole flow's audit events inline.
/// Deployer role; refuses on a standby with error code STANDBY_NODE.
///
/// The method to run.
/// Flat JSON object of parameters (validated against the method's schema); null = none.
public record FlowDebugRunMethodCommand(int ApiMethodId, JsonElement? Parameters);
///
/// Flow Debugger Live run of a value-change trigger (design 2026-09-05 §5.3): writes
/// to on the instance through the
/// traced routed-write path, then polls the site for the traced run(s) the change spawned.
///
/// The instance to write to.
/// Canonical attribute name.
/// Canonical string value to write.
/// How long to wait for a spawned run before reporting NO_TRIGGER_WITHIN_WINDOW.
public record FlowDebugRunValueChangeCommand(int InstanceId, string AttributeName, string Value, int WaitSeconds = 45);
///
/// Flow Debugger Live run of a site script by name (design 2026-09-08). The runner resolves the
/// script's effective definition from the flattened instance configuration and branches on its
/// trigger kind: a ValueChange/Conditional script is fired by WRITING its monitored
/// attribute () and polling for the spawned run, exactly like
/// ; every other kind is invoked DIRECTLY through the
/// traced routed-call path with . Deployer role; refuses on a standby
/// with STANDBY_NODE.
///
/// The instance the script belongs to.
/// Canonical script name from the flattened configuration (case-insensitive).
/// Call kinds: flat JSON object validated against the script's ParameterDefinitions; null = none.
/// Write kinds: canonical string value to write to the trigger's attribute.
/// Write kinds: how long to wait for a spawned run before NO_TRIGGER_WITHIN_WINDOW.
public record FlowDebugRunScriptCommand(
int InstanceId,
string ScriptName,
JsonElement? Parameters,
string? Value,
int WaitSeconds = 45);
///
/// Flow Debugger Replay (design 2026-09-05 §7.1): returns the audit events of the execution
/// tree that belongs to, from the central store.
///
/// Any execution id in the chain.
public record FlowDebugReplayCommand(Guid ExecutionId);
/// The result of a Flow Debugger run or replay: the flow's audit events plus outcome metadata.
/// The root execution id (the inbound request / the value-change write).
/// True when the run finished (or the replay found rows); false on timeout / no trigger.
/// Human-readable failure, null on success.
/// Machine-readable failure code, null on success.
/// The flow's audit events, oldest first — feed FlowGraphBuilder.Build.
/// True when the inline event list was capped (the audit rows remain complete).
/// When the run started.
/// When the run finished (or the replay was served).
///
/// Step-logs (D7, 2026-09-09): true when the inline FlowTraceCollector dropped one
/// or more low-priority ScriptLog rows to protect room for step rows — the run's log lines
/// are incomplete inline, but Replay (which reads the audit store, never truncated) is complete.
///
public record FlowDebugRunResult(
Guid RootExecutionId,
bool Completed,
string? Error,
string? ErrorCode,
IReadOnlyList Events,
bool Truncated,
DateTimeOffset StartedAtUtc,
DateTimeOffset FinishedAtUtc,
bool LogsTruncated = false);