"""Tests for ``arautopilot.core.modes``."""

from __future__ import annotations

import pytest

from arautopilot.core.modes import AutopilotMode, is_available_in_phase


def test_all_modes_have_string_values() -> None:
    """Every enum member must use a kebab/snake-style string value (for serialisation)."""
    for m in AutopilotMode:
        assert isinstance(m.value, str)
        assert m.value == m.value.lower()
        assert " " not in m.value


def test_phase_1_modes_are_exactly_the_five_brief_modes() -> None:
    expected = {
        AutopilotMode.STANDBY,
        AutopilotMode.HEADING_HOLD,
        AutopilotMode.TRUE_COURSE,
        AutopilotMode.TRACK_KEEPING,
        AutopilotMode.DODGE,
    }
    got = {m for m in AutopilotMode if is_available_in_phase(m, 1)}
    assert got == expected


def test_phase_2_modes_include_phase_1_plus_wind_modes() -> None:
    phase_2 = {m for m in AutopilotMode if is_available_in_phase(m, 2)}
    expected = {
        AutopilotMode.STANDBY,
        AutopilotMode.HEADING_HOLD,
        AutopilotMode.TRUE_COURSE,
        AutopilotMode.TRACK_KEEPING,
        AutopilotMode.DODGE,
        AutopilotMode.APPARENT_WIND,
        AutopilotMode.TRUE_WIND,
        AutopilotMode.AUTO_TACK,
    }
    assert phase_2 == expected


@pytest.mark.parametrize(
    "mode",
    [AutopilotMode.APPARENT_WIND, AutopilotMode.TRUE_WIND, AutopilotMode.AUTO_TACK],
)
def test_wind_modes_disabled_in_phase_1(mode: AutopilotMode) -> None:
    assert not is_available_in_phase(mode, 1)


@pytest.mark.parametrize("phase", [0, 3, 99, -1])
def test_unknown_phases_disable_everything(phase: int) -> None:
    for m in AutopilotMode:
        assert not is_available_in_phase(m, phase)
