namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.IntegrationTests.DL205;

/// <summary>
///     Tag map for the AutomationDirect DL205 device class. Mirrors what the pymodbus
///     <c>dl205.json</c> profile in <c>Docker/profiles/dl205.json</c> exposes (or the real PLC, when
///     <see cref="ModbusSimulatorFixture"/> is pointed at one).
/// </summary>
/// <remarks>
///     This is the scaffold — each tag is deliberately generic so the smoke test has stable
///     addresses to read. Device-specific quirk tests (word order, max-register, register-zero
///     access, etc.) will land in their own test classes alongside this profile as the user
///     validates each behavior in pymodbus; see <c>docs/v2/modbus-test-plan.md</c> §per-device
///     quirk catalog for the checklist.
/// </remarks>
public static class DL205Profile
{
    /// <summary>
    ///     Holding register the smoke test writes + reads. Address 200 is the first cell of the
    ///     scratch HR range in both <c>Docker/profiles/standard.json</c> (HR[200..209] = 0) and
    ///     <c>Docker/profiles/dl205.json</c> (HR[4096..4103] added in PR 43 for the same purpose), so
    ///     the smoke test runs identically against either simulator profile. Originally
    ///     targeted HR[100] — moved to HR[200] when the standard profile claimed HR[100] as
    ///     the auto-incrementing register that drives subscribe-and-receive tests.
    /// </summary>
    public const ushort SmokeHoldingRegister = 200;

    /// <summary>Value the smoke test writes then reads back to assert round-trip integrity.</summary>
    public const short SmokeHoldingValue = 1234;

    /// <summary>Builds Modbus driver options for the DL205 test profile.</summary>
    /// <param name="host">The host or IP address of the Modbus device.</param>
    /// <param name="port">The port number of the Modbus device.</param>
    /// <returns>Configured Modbus driver options for DL205.</returns>
    public static ModbusDriverOptions BuildOptions(string host, int port) => new()
    {
        Host = host,
        Port = port,
        UnitId = 1,
        Timeout = TimeSpan.FromSeconds(2),
        RawTags = ModbusRawTags.Entries([
            new ModbusTagDefinition(
                Name: "Smoke_HReg200",
                Region: ModbusRegion.HoldingRegisters,
                Address: SmokeHoldingRegister,
                DataType: ModbusDataType.Int16,
                Writable: true),
        ]),
        // Disable the background probe loop — integration tests drive reads explicitly and
        // the probe would race with assertions.
        Probe = new ModbusProbeOptions { Enabled = false },
    };
}
