"""WF02 helper command dispatcher for Robot integration tests."""

from __future__ import annotations

import sys
from collections.abc import Callable
from pathlib import Path

_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
    sys.path.insert(0, _SRC)

_ROBOT = str(Path(__file__).resolve().parent)
if _ROBOT not in sys.path:
    sys.path.insert(0, _ROBOT)

from helpers_common import reset_global_state  # noqa: E402
from wf02_test_generation_artifacts import (  # noqa: E402
    wf02_mocked_generation_artifacts,
)
from wf02_test_generation_commands import command_map  # noqa: E402
from wf02_test_generation_validation import wf02_coverage_validation  # noqa: E402

COMMANDS: dict[str, Callable[[], None]] = command_map(
    mocked_generation_artifacts=wf02_mocked_generation_artifacts,
    coverage_validation=wf02_coverage_validation,
)


def main() -> int:
    """Command dispatcher used by Robot ``Run Process`` calls."""
    if len(sys.argv) < 2 or sys.argv[1] not in COMMANDS:
        print(
            "Usage: helper_wf02_test_generation.py "
            "<trusted-lifecycle|mocked-generation-artifacts|coverage-validation"
            "|path-safety-guardrails>",
            file=sys.stderr,
        )
        return 1

    reset_global_state()
    COMMANDS[sys.argv[1]]()
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
