from __future__ import annotations

from tests.pipeline_setup.suite_02_pipeline.pipeline_intent_rag.cli import ReindexCliArgs, RunCliArgs, _parse_args


def test_cli_parse_run_defaults_with_legacy_syntax() -> None:
    parsed = _parse_args(["--mode", "router_only"])
    assert parsed.command == "run"
    assert isinstance(parsed.payload, RunCliArgs)
    args = parsed.payload

    assert args.mode == "router_only"
    assert args.case_ids == ()
    assert args.test_name == "cli_router_only"
    assert args.verbose is False


def test_cli_parse_run_with_overrides() -> None:
    parsed = _parse_args(
        [
            "run",
            "--mode",
            "router_rag",
            "--case-id",
            "c1",
            "--case-id",
            "c2",
            "--rag-session-id",
            "sid-1",
            "--reindex-repo-path",
            "/tmp/repo",
            "--reindex-project-id",
            "proj-1",
            "--test-name",
            "run-x",
        ]
    )
    assert parsed.command == "run"
    assert isinstance(parsed.payload, RunCliArgs)
    args = parsed.payload

    assert args.mode == "router_rag"
    assert args.case_ids == ("c1", "c2")
    assert args.rag_session_id == "sid-1"
    assert args.reindex_repo_path == "/tmp/repo"
    assert args.reindex_project_id == "proj-1"
    assert args.test_name == "run-x"
    assert args.verbose is False


def test_cli_parse_run_verbose_alias() -> None:
    parsed = _parse_args(["run", "--mode", "router_rag", "--debug"])
    assert parsed.command == "run"
    assert isinstance(parsed.payload, RunCliArgs)
    assert parsed.payload.verbose is True


def test_cli_parse_reindex() -> None:
    parsed = _parse_args(["reindex", "--repo-path", "/tmp/repo", "--project-id", "proj-1"])
    assert parsed.command == "reindex"
    assert isinstance(parsed.payload, ReindexCliArgs)
    args = parsed.payload

    assert args.repo_path == "/tmp/repo"
    assert args.project_id == "proj-1"
