using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.AbCip;

namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Tests;

[Trait("Category", "Unit")]
public sealed class AbCipStatusMapperTests
{
    [Theory]
    [InlineData((byte)0x00, AbCipStatusMapper.Good)]
    [InlineData((byte)0x04, AbCipStatusMapper.BadNodeIdUnknown)]
    [InlineData((byte)0x05, AbCipStatusMapper.BadNodeIdUnknown)]
    [InlineData((byte)0x06, AbCipStatusMapper.GoodMoreData)]
    [InlineData((byte)0x08, AbCipStatusMapper.BadNotSupported)]
    [InlineData((byte)0x0A, AbCipStatusMapper.BadOutOfRange)]
    [InlineData((byte)0x13, AbCipStatusMapper.BadOutOfRange)]
    [InlineData((byte)0x0B, AbCipStatusMapper.Good)]
    [InlineData((byte)0x0E, AbCipStatusMapper.BadNotWritable)]
    [InlineData((byte)0x10, AbCipStatusMapper.BadDeviceFailure)]
    [InlineData((byte)0x16, AbCipStatusMapper.BadNodeIdUnknown)]
    [InlineData((byte)0xFF, AbCipStatusMapper.BadInternalError)]
    public void MapCipGeneralStatus_maps_known_codes(byte status, uint expected)
    {
        AbCipStatusMapper.MapCipGeneralStatus(status).ShouldBe(expected);
    }

    [Theory]
    [InlineData(0, AbCipStatusMapper.Good)]
    [InlineData(1, AbCipStatusMapper.GoodMoreData)] // PLCTAG_STATUS_PENDING
    [InlineData(-5, AbCipStatusMapper.BadTimeout)]
    [InlineData(-7, AbCipStatusMapper.BadCommunicationError)]
    [InlineData(-14, AbCipStatusMapper.BadNodeIdUnknown)]
    [InlineData(-16, AbCipStatusMapper.BadNotWritable)]
    [InlineData(-17, AbCipStatusMapper.BadOutOfRange)]
    [InlineData(-99, AbCipStatusMapper.BadCommunicationError)] // unknown negative → generic comms failure
    public void MapLibplctagStatus_maps_known_codes(int status, uint expected)
    {
        AbCipStatusMapper.MapLibplctagStatus(status).ShouldBe(expected);
    }
}
