using Opc.Ua;
using Opc.Ua.Server;

namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;

/// <summary>
///     <see cref="StandardServer"/> subclass that wires in the v2 <see cref="OtOpcUaNodeManager"/>.
///     Exposes the live node manager after start so callers (<see cref="OpcUaApplicationHost"/>,
///     the fused Host's DI binding) can wrap it in a <see cref="SdkAddressSpaceSink"/> and hand
///     it to <c>OpcUaPublishActor</c>.
/// </summary>
public sealed class OtOpcUaSdkServer : StandardServer
{
    private OtOpcUaNodeManager? _otOpcUaNodeManager;

    /// <summary>The custom node manager once <c>StartAsync</c> has called
    /// <see cref="CreateMasterNodeManager"/>. Null until the SDK has bootstrapped.</summary>
    public OtOpcUaNodeManager? NodeManager => _otOpcUaNodeManager;

    /// <inheritdoc />
    protected override MasterNodeManager CreateMasterNodeManager(
        IServerInternal server, ApplicationConfiguration configuration)
    {
        _otOpcUaNodeManager = new OtOpcUaNodeManager(server, configuration);
        return new MasterNodeManager(server, configuration, dynamicNamespaceUri: null, _otOpcUaNodeManager);
    }
}
