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

namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Browse;

/// <summary>
///     Maps Galaxy <c>mx_data_type</c> integer codes to <see cref="DriverDataType"/>.
///     Ported from the legacy <c>GalaxyProxyDriver.MapDataType</c> with the same fallback
///     to <see cref="DriverDataType.String"/> for unknown codes — keeps wire compatibility
///     with deployed configs while we tighten this through the parity matrix.
/// </summary>
/// <remarks>
///     Code <c>6</c> (Int64) extends the contiguous 0..5 scheme so the map covers the same
///     seven Galaxy data types <c>MxValueDecoder</c> / <c>MxValueEncoder</c> already decode
///     and encode (Boolean, Int32, Int64, Float32, Float64, String, DateTime). Without it an
///     Int64 attribute fell through to the <see cref="DriverDataType.String"/> default,
///     creating a String address-space node while runtime reads decoded a boxed <c>long</c> —
///     a metadata / coercion mismatch.
/// </remarks>
internal static class DataTypeMap
{
    /// <summary>Maps an MXAccess data type ID to a driver data type.</summary>
    /// <param name="mxDataType">The MXAccess data type ID.</param>
    /// <returns>The corresponding <see cref="DriverDataType"/>, or <see cref="DriverDataType.String"/> for unknown codes.</returns>
    public static DriverDataType Map(int mxDataType) => mxDataType switch
    {
        0 => DriverDataType.Boolean,
        1 => DriverDataType.Int32,
        2 => DriverDataType.Float32,
        3 => DriverDataType.Float64,
        4 => DriverDataType.String,
        5 => DriverDataType.DateTime,
        6 => DriverDataType.Int64,
        _ => DriverDataType.String,
    };
}
