namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Scripting;

/// <summary>
/// Advisory notification that one or more script-bearing artifacts changed on this
/// node. It is <b>at-least-once</b> and is published only <b>AFTER</b> the mutating
/// transaction commits — never inside it (a notification for a rolled-back write is
/// worse than a missed one).
/// <para>
/// Consumers MUST invalidate any compiled/cached artifact keyed by these names, and
/// MUST ALSO be able to self-heal <i>without</i> the notification (e.g. a
/// content-hash / revision check on next use) — this bus is <b>in-process, per
/// node</b>; cross-node and failover propagation is the consumer's responsibility.
/// See <c>docs/plans/2026-07-08-script-artifact-invalidation-contract.md</c>.
/// </para>
/// </summary>
/// <param name="ArtifactKind">One of <see cref="ScriptArtifactKinds"/> — the kind of artifact that changed.</param>
/// <param name="Names">The post-resolution (renamed) artifact names that changed.</param>
/// <param name="Source">Origin of the change: <c>"BundleImport"</c>, <c>"Management"</c>, or <c>"FailoverActivation"</c>.</param>
/// <param name="OccurredAtUtc">When the committing transaction completed.</param>
public sealed record ScriptArtifactsChanged(
    string ArtifactKind,
    IReadOnlyList<string> Names,
    string Source,
    DateTimeOffset OccurredAtUtc);

/// <summary>
/// The canonical set of <see cref="ScriptArtifactsChanged.ArtifactKind"/> values —
/// the artifact classes that carry compiled/cached script and therefore need
/// invalidation when their definition changes.
/// </summary>
public static class ScriptArtifactKinds
{
    /// <summary>An Inbound API method (its script handler is compiled and cached).</summary>
    public const string ApiMethod = "ApiMethod";

    /// <summary>A shared script (compiled inline at every call site that references it).</summary>
    public const string SharedScript = "SharedScript";

    /// <summary>A template (its scripts flatten into every instance built from it).</summary>
    public const string Template = "Template";
}
