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

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

/// <summary>
/// In-process, per-node publish/subscribe seam for
/// <see cref="ScriptArtifactsChanged"/>. Producers (e.g. the Transport bundle
/// importer, the ManagementActor script-editing paths) publish AFTER their mutating
/// transaction commits; consumers (e.g. the Inbound API compiled-handler cache)
/// subscribe and evict.
/// <para>
/// A conforming implementation MUST swallow-and-log any exception thrown by a
/// subscriber's handler — a misbehaving consumer must never fault a producer's
/// commit path.
/// </para>
/// </summary>
public interface IScriptArtifactChangeBus
{
    /// <summary>Publishes a change notification to every current subscriber. Never throws on a subscriber fault.</summary>
    /// <param name="notification">The change notification to deliver.</param>
    void Publish(ScriptArtifactsChanged notification);

    /// <summary>Subscribes a handler; dispose the returned token to unsubscribe.</summary>
    /// <param name="handler">The handler invoked for each published notification.</param>
    /// <returns>A disposable that removes the subscription when disposed.</returns>
    IDisposable Subscribe(Action<ScriptArtifactsChanged> handler);
}
