using Microsoft.Extensions.Options;
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;

namespace ZB.MOM.WW.ScadaBridge.Host.Tests;

/// <summary>
/// Tests for NodeIdentityProvider — surfaces the operator-configured semantic
/// node name (e.g. node-a / node-b / central-a / central-b) used by downstream
/// audit writers to stamp the SourceNode column.
/// </summary>
public class NodeIdentityProviderTests
{
    private static INodeIdentityProvider BuildProvider(string nodeName)
    {
        var options = Options.Create(new NodeOptions { NodeName = nodeName });
        return new NodeIdentityProvider(options);
    }

    [Fact]
    public void NodeIdentityProvider_returns_configured_NodeName()
    {
        var provider = BuildProvider("central-a");

        Assert.Equal("central-a", provider.NodeName);
    }

    [Fact]
    public void NodeIdentityProvider_returns_null_when_NodeName_unset()
    {
        var provider = BuildProvider(string.Empty);

        Assert.Null(provider.NodeName);
    }

    [Fact]
    public void NodeIdentityProvider_returns_null_when_NodeName_whitespace()
    {
        var provider = BuildProvider("   ");

        Assert.Null(provider.NodeName);
    }

    [Fact]
    public void NodeIdentityProvider_trims_whitespace()
    {
        var provider = BuildProvider("  node-a  ");

        Assert.Equal("node-a", provider.NodeName);
    }
}
