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

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

/// <summary>
///     Maps the library's AggregateType enum to OPC UA aggregate function NodeIds.
/// </summary>
public static class AggregateTypeMapper
{
    /// <summary>
    ///     Returns the OPC UA NodeId for the specified aggregate type.
    /// </summary>
    /// <param name="aggregate">The aggregate type to map to a NodeId.</param>
    /// <returns>The OPC UA NodeId for the aggregate function.</returns>
    public static NodeId ToNodeId(AggregateType aggregate)
    {
        return aggregate switch
        {
            AggregateType.Average => ObjectIds.AggregateFunction_Average,
            AggregateType.Minimum => ObjectIds.AggregateFunction_Minimum,
            AggregateType.Maximum => ObjectIds.AggregateFunction_Maximum,
            AggregateType.Count => ObjectIds.AggregateFunction_Count,
            AggregateType.Start => ObjectIds.AggregateFunction_Start,
            AggregateType.End => ObjectIds.AggregateFunction_End,
            AggregateType.StandardDeviation => ObjectIds.AggregateFunction_StandardDeviationPopulation,
            _ => throw new ArgumentOutOfRangeException(nameof(aggregate), aggregate, "Unknown AggregateType value.")
        };
    }
}