"""
Unit tests for services/complex_manager_router.py — the centralized,
deterministic intent -> Navigation Card mapping used by FR-07.5 (Routing
Complex Manager Tasks). Pure-function tests: no LLM, no erp-api, no graph.
"""

from services.complex_manager_router import (
    COMPLEX_MANAGER_INTENTS,
    COMPLEX_MANAGER_ROUTE_CONFIG,
    route_complex_manager_task,
)

EXPECTED_TARGETS = {
    "large_team_review": "/team/review",
    "bulk_approvals": "/payroll/approvals/bulk",
    "shift_planning": "/shifts/planner",
    "comparative_reporting": "/reports/comparative",
}


class TestRouteComplexManagerTask:

    def test_all_four_categories_are_configured(self):
        assert COMPLEX_MANAGER_INTENTS == set(EXPECTED_TARGETS.keys())
        assert set(COMPLEX_MANAGER_ROUTE_CONFIG.keys()) == COMPLEX_MANAGER_INTENTS

    def test_each_intent_maps_to_the_correct_deep_link_target(self):
        for intent, expected_path in EXPECTED_TARGETS.items():
            navigation = route_complex_manager_task(intent)
            assert navigation is not None
            assert navigation["button"]["path"] == expected_path

    def test_navigation_card_shape(self):
        navigation = route_complex_manager_task("bulk_approvals")
        assert navigation["category"] == "bulk_approvals"
        assert navigation["title"] == "Bulk Approvals"
        assert navigation["message"] == (
            "Bulk approvals are best handled on the full web dashboard. "
            "Click below to open the Bulk Approvals page."
        )
        assert navigation["button"] == {
            "label": "Open Bulk Approvals Page",
            "path": "/payroll/approvals/bulk",
        }

    def test_unknown_intent_returns_none_instead_of_inventing_a_destination(self):
        assert route_complex_manager_task("not_a_real_intent") is None

    def test_unknown_intent_logs_route_not_configured(self, caplog):
        with caplog.at_level("ERROR", logger="services.complex_manager_router"):
            route_complex_manager_task("some_unmapped_intent")
        assert "COMPLEX_MANAGER_ROUTE_NOT_CONFIGURED" in caplog.text
