using Opc.Ua;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Client.Shared.Helpers;
using ZB.MOM.WW.OtOpcUa.Client.Shared.Models;

namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Tests.Helpers;

public class AggregateTypeMapperTests
{
    [Theory]
    [InlineData(AggregateType.Average)]
    [InlineData(AggregateType.Minimum)]
    [InlineData(AggregateType.Maximum)]
    [InlineData(AggregateType.Count)]
    [InlineData(AggregateType.Start)]
    [InlineData(AggregateType.End)]
    [InlineData(AggregateType.StandardDeviation)]
    public void ToNodeId_ReturnsNonNullForAllValues(AggregateType aggregate)
    {
        var nodeId = AggregateTypeMapper.ToNodeId(aggregate);
        nodeId.ShouldNotBeNull();
        nodeId.IsNullNodeId.ShouldBeFalse();
    }

    [Fact]
    public void ToNodeId_Average_MapsCorrectly()
    {
        AggregateTypeMapper.ToNodeId(AggregateType.Average).ShouldBe(ObjectIds.AggregateFunction_Average);
    }

    [Fact]
    public void ToNodeId_Minimum_MapsCorrectly()
    {
        AggregateTypeMapper.ToNodeId(AggregateType.Minimum).ShouldBe(ObjectIds.AggregateFunction_Minimum);
    }

    [Fact]
    public void ToNodeId_Maximum_MapsCorrectly()
    {
        AggregateTypeMapper.ToNodeId(AggregateType.Maximum).ShouldBe(ObjectIds.AggregateFunction_Maximum);
    }

    [Fact]
    public void ToNodeId_Count_MapsCorrectly()
    {
        AggregateTypeMapper.ToNodeId(AggregateType.Count).ShouldBe(ObjectIds.AggregateFunction_Count);
    }

    [Fact]
    public void ToNodeId_Start_MapsCorrectly()
    {
        AggregateTypeMapper.ToNodeId(AggregateType.Start).ShouldBe(ObjectIds.AggregateFunction_Start);
    }

    [Fact]
    public void ToNodeId_End_MapsCorrectly()
    {
        AggregateTypeMapper.ToNodeId(AggregateType.End).ShouldBe(ObjectIds.AggregateFunction_End);
    }

    [Fact]
    public void ToNodeId_StandardDeviation_MapsCorrectly()
    {
        AggregateTypeMapper.ToNodeId(AggregateType.StandardDeviation)
            .ShouldBe(ObjectIds.AggregateFunction_StandardDeviationPopulation);
    }

    [Fact]
    public void ToNodeId_InvalidValue_Throws()
    {
        Should.Throw<ArgumentOutOfRangeException>(() =>
            AggregateTypeMapper.ToNodeId((AggregateType)99));
    }
}