import pytest

from flashops_control.engine.states import IllegalTransition, assert_run_transition
from flashops_control.enums import RunState


def test_happy_path_transitions_are_allowed():
    assert_run_transition(RunState.QUEUED.value, RunState.PREFLIGHT.value)
    assert_run_transition(RunState.PREFLIGHT.value, RunState.RUNNING.value)
    assert_run_transition(RunState.RUNNING.value, RunState.RECOVERING.value)
    assert_run_transition(RunState.RECOVERING.value, RunState.RUNNING.value)
    assert_run_transition(RunState.RUNNING.value, RunState.COMPLETED.value)


def test_terminal_state_cannot_transition():
    with pytest.raises(IllegalTransition):
        assert_run_transition(RunState.COMPLETED.value, RunState.RUNNING.value)


def test_rejected_cannot_be_resumed():
    with pytest.raises(IllegalTransition):
        assert_run_transition(RunState.REJECTED.value, RunState.QUEUED.value)
