namespace ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.Pickers;

/// <summary>
/// Pure static helper that converts Modbus register-type + offset + length into
/// the canonical address string used by the Modbus driver (e.g. 4x00001-1).
/// Extracted so unit tests can call it without bUnit.
/// </summary>
public static class ModbusAddressBuilder
{
    /// <summary>Builds the canonical Modbus address string for a register type, offset, and length.</summary>
    /// <param name="regType">The register type (e.g. Coil, DiscreteInput, Input, Holding).</param>
    /// <param name="offset">The zero-based register/coil offset.</param>
    /// <param name="length">The number of registers/coils spanned.</param>
    /// <returns>The canonical address string (e.g. <c>4x00001-1</c>).</returns>
    public static string Build(string regType, int offset, int length)
    {
        var prefix = regType switch
        {
            "Coil"          => "0x",
            "DiscreteInput" => "1x",
            "Input"         => "3x",
            "Holding"       => "4x",
            _               => "4x",
        };
        return $"{prefix}{offset:00000}-{length}";
    }
}
