"""Tests for run_meeting CLI argument parsing."""

from __future__ import annotations

from pathlib import Path

from run_meeting import parse_args


class TestParseArgs:
    """Tests for CLI argument parsing."""

    def test_parse_required_args(self) -> None:
        args = parse_args(["--topic", "Test topic", "--agents", "arch,devops"])
        assert args.topic == "Test topic"
        assert args.agents == "arch,devops"

    def test_parse_optional_args(self) -> None:
        args = parse_args([
            "--topic", "Test",
            "--agents", "a,b",
            "--max-rounds", "15",
            "--agents-dir", "/custom/agents",
            "--output-dir", "/custom/reports",
        ])
        assert args.max_rounds == 15
        assert args.agents_dir == "/custom/agents"
        assert args.output_dir == "/custom/reports"

    def test_default_values(self) -> None:
        args = parse_args(["--topic", "T", "--agents", "a"])
        assert args.max_rounds is None  # defaults to None, main() resolves to 10
        assert args.agents_dir == "agents"
        assert args.output_dir == "reports"

    def test_default_max_rounds_is_10(self) -> None:
        """Default max_rounds is None at parse level (main() resolves to 10)."""
        args = parse_args(["--topic", "T", "--agents", "a"])
        assert args.max_rounds is None

    def test_cli_context_argument(self) -> None:
        """--context provides inline context string."""
        args = parse_args(["--topic", "T", "--agents", "a", "--context", "Some background"])
        assert args.context == "Some background"

    def test_cli_context_file_reads_content(self, tmp_path: Path) -> None:
        """--context-file reads context from a file."""
        ctx_file = tmp_path / "brief.md"
        ctx_file.write_text("# Brief\n\nDetailed background.", encoding="utf-8")
        args = parse_args([
            "--topic", "T",
            "--agents", "a",
            "--context-file", str(ctx_file),
        ])
        assert args.context_file == str(ctx_file)

    def test_context_defaults_empty(self) -> None:
        """--context defaults to empty string."""
        args = parse_args(["--topic", "T", "--agents", "a"])
        assert args.context == ""
        assert args.context_file is None

    def test_scenario_argument(self) -> None:
        """--scenario specifies a preset scenario."""
        args = parse_args(["--topic", "T", "--scenario", "product_review"])
        assert args.scenario == "product_review"
        assert args.agents is None

    def test_auto_select_argument(self) -> None:
        """--auto-select enables PM auto agent selection."""
        args = parse_args(["--topic", "T", "--auto-select"])
        assert args.auto_select is True

    def test_list_scenarios_argument(self) -> None:
        """--list-scenarios flag is recognized."""
        args = parse_args(["--list-scenarios"])
        assert args.list_scenarios is True

    def test_agents_not_required_with_scenario(self) -> None:
        """--agents is not required when --scenario is provided."""
        args = parse_args(["--topic", "T", "--scenario", "product_review"])
        assert args.scenario == "product_review"

    def test_agents_not_required_with_auto_select(self) -> None:
        """--agents is not required when --auto-select is provided."""
        args = parse_args(["--topic", "T", "--auto-select"])
        assert args.auto_select is True

    def test_interactive_argument(self) -> None:
        """--interactive flag is recognized."""
        args = parse_args(["--topic", "T", "--agents", "a", "--interactive"])
        assert args.interactive is True

    def test_interactive_defaults_false(self) -> None:
        """--interactive defaults to False."""
        args = parse_args(["--topic", "T", "--agents", "a"])
        assert args.interactive is False

    def test_context_budget_argument(self) -> None:
        """--context-budget sets the token budget."""
        args = parse_args(["--topic", "T", "--agents", "a", "--context-budget", "4000"])
        assert args.context_budget == 4000

    def test_context_budget_default(self) -> None:
        """--context-budget defaults to 6000."""
        args = parse_args(["--topic", "T", "--agents", "a"])
        assert args.context_budget == 6000

    def test_no_compact_flag(self) -> None:
        """--no-compact flag disables compression."""
        args = parse_args(["--topic", "T", "--agents", "a", "--no-compact"])
        assert args.no_compact is True

    def test_no_compact_defaults_false(self) -> None:
        """--no-compact defaults to False."""
        args = parse_args(["--topic", "T", "--agents", "a"])
        assert args.no_compact is False
