using Modules.WMS.Picking.Shared;
using Xunit;

namespace Modules.WMS.Picking.Tests;

public sealed class PickingScanStateMachineTests
{
    [Fact]
    public void LocationMustBeConfirmedBeforeItem()
    {
        var state = new PickingScanState(false, "A-03-02", "LOC-A-03-02", "880123", 2, 0);
        var result = PickingScanStateMachine.Decide(state, "880123");

        Assert.Equal(PickingScanDecisionKind.RejectLocation, result.Kind);
        Assert.False(result.Accepted);
    }

    [Fact]
    public void CorrectLocationMovesToItemStageWithoutChangingQuantity()
    {
        var state = new PickingScanState(false, "A-03-02", "LOC-A-03-02", "880123", 2, 0);
        var result = PickingScanStateMachine.Decide(state, "LOC-A-03-02");

        Assert.Equal(PickingScanDecisionKind.AcceptLocation, result.Kind);
        Assert.Null(result.NewPickedQty);
    }

    [Fact]
    public void CorrectItemIncrementsExactlyOneUnit()
    {
        var state = new PickingScanState(true, "A-03-02", "LOC-A-03-02", "880123", 2, 0);
        var result = PickingScanStateMachine.Decide(state, "880123");

        Assert.Equal(PickingScanDecisionKind.AcceptItem, result.Kind);
        Assert.Equal(1m, result.NewPickedQty);
        Assert.False(result.LineCompleted);
    }

    [Fact]
    public void RequiredQuantityCompletesLine()
    {
        var state = new PickingScanState(true, "A-03-02", "LOC-A-03-02", "880123", 2, 1);
        var result = PickingScanStateMachine.Decide(state, "880123");

        Assert.Equal(2m, result.NewPickedQty);
        Assert.True(result.LineCompleted);
    }
}
