using KArtSell.Modules.SignalEngine.Domain;

namespace KArtSell.SignalEngine.UnitTests;

public sealed class ReentryStateMachineTests
{
    [Fact]
    public void Reentry_requires_wait_spacing_trend_breakout_and_asset_confirmation()
    {
        var state = ReentryStateMachine.Evaluate(
            ReentryState.Watching,
            new ReentryInput(10, 10, true, true, true, false, false));

        Assert.Equal(ReentryState.Ready, state);
    }

    [Fact]
    public void Missing_asset_confirmation_keeps_watch_open()
    {
        var state = ReentryStateMachine.Evaluate(
            ReentryState.Watching,
            new ReentryInput(10, 10, true, true, false, false, false));

        Assert.Equal(ReentryState.Watching, state);
    }

    [Fact]
    public void Executed_stage_moves_to_reentered_then_watching_when_stages_remain()
    {
        var reentered = ReentryStateMachine.Evaluate(
            ReentryState.Ready,
            new ReentryInput(10, 10, true, true, true, false, false,
                StageExecuted: true, HasRemainingStages: true));

        var next = ReentryStateMachine.Evaluate(
            reentered,
            new ReentryInput(10, 0, true, true, true, false, false,
                HasRemainingStages: true));

        Assert.Equal(ReentryState.Reentered, reentered);
        Assert.Equal(ReentryState.Watching, next);
    }

    [Fact]
    public void Last_executed_stage_moves_to_open()
    {
        var next = ReentryStateMachine.Evaluate(
            ReentryState.Reentered,
            new ReentryInput(20, 10, true, true, true, false, false,
                HasRemainingStages: false));

        Assert.Equal(ReentryState.Open, next);
    }

    [Fact]
    public void Hard_impairment_closes_watch()
    {
        var state = ReentryStateMachine.Evaluate(
            ReentryState.Watching,
            new ReentryInput(100, 100, true, true, true, true, false));

        Assert.Equal(ReentryState.Closed, state);
    }
}
