namespace ZB.MOM.WW.OtOpcUa.Commons.OpcUa;

/// <summary>
///     Writes the OPC UA Server object's <c>ServiceLevel</c> Variable (0–255). Production binds
///     a sink that pokes the SDK's ServiceLevel node; tests + dev mode bind
///     <see cref="NullServiceLevelPublisher"/> which just records the most recently set level
///     for inspection.
/// </summary>
public interface IServiceLevelPublisher
{
    /// <summary>Publishes the service level value to the OPC UA Server object.</summary>
    /// <param name="serviceLevel">The service level value (0-255).</param>
    void Publish(byte serviceLevel);
}

/// <summary>No-op default that retains the last-written ServiceLevel in
/// <see cref="LastPublished"/>. Used by dev mode + verified by tests.</summary>
public sealed class NullServiceLevelPublisher : IServiceLevelPublisher
{
    public static readonly NullServiceLevelPublisher Instance = new();
    private NullServiceLevelPublisher() { }

    /// <summary>Gets the last published service level value.</summary>
    public byte LastPublished { get; private set; }

    /// <inheritdoc />
    public void Publish(byte serviceLevel) => LastPublished = serviceLevel;
}
