using ZB.MOM.WW.OtOpcUa.Core.Abstractions;

namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;

/// <summary>Map a PCCC data type to the driver-surface <see cref="DriverDataType"/>.</summary>
public static class AbLegacyDataTypeExtensions
{
    /// <summary>Converts an AbLegacyDataType to the corresponding DriverDataType.</summary>
    /// <param name="t">The PCCC data type to convert.</param>
    /// <returns>The mapped driver data type.</returns>
    public static DriverDataType ToDriverDataType(this AbLegacyDataType t) => t switch
    {
        AbLegacyDataType.Bit => DriverDataType.Boolean,
        AbLegacyDataType.Int or AbLegacyDataType.AnalogInt => DriverDataType.Int32,
        AbLegacyDataType.Long => DriverDataType.Int32,       // matches Modbus/AbCip 64→32 gap
        AbLegacyDataType.Float => DriverDataType.Float32,
        AbLegacyDataType.String => DriverDataType.String,
        AbLegacyDataType.TimerElement or AbLegacyDataType.CounterElement
            or AbLegacyDataType.ControlElement => DriverDataType.Int32,
        _ => DriverDataType.Int32,
    };
}
