"""FR-02's three categories, which FR-09 then reports on.

The line that matters: "HRMS action/request" means the turn TOUCHES HRMS DATA
and is therefore governed by the permission framework — not that it mutates
anything. So `leave_balance` sits with `apply_leave`. Splitting them by
read-vs-write would report "how many leaves do I have" as an HR *query* when
it is an HRMS lookup, and would be an engineering distinction the ticket
never asks for.
"""
import pytest

from services.hr_graph import (
    conversation_category,
    CATEGORY_GENERAL,
    CATEGORY_HR_QUERY,
    CATEGORY_HRMS_ACTION,
)


@pytest.mark.parametrize("intent", [
    "leave_balance", "leave_status",          # reads — still HRMS
    "apply_leave", "cancel_leave",            # writes
    "leave_eligibility",
    "manager_leave_request_lookup", "manager_leave_approval",
    "attendance",
])
def test_anything_touching_hrms_data_is_an_hrms_action(intent):
    assert conversation_category(intent, is_hr=True) == CATEGORY_HRMS_ACTION


@pytest.mark.parametrize("intent", [
    "policy", "general_hr", "compliance", "benefits",
    "onboarding", "training", "recruitment",
])
def test_hr_answered_from_documents_is_an_hr_query(intent):
    """No employee record is read, so no permission question arises."""
    assert conversation_category(intent, is_hr=True) == CATEGORY_HR_QUERY


@pytest.mark.parametrize("intent", ["non_hr", "small_talk", "", "anything"])
def test_not_hr_is_general_whatever_the_intent_says(intent):
    """is_hr is the deciding signal — a general turn is general even if the
    classifier left some intent string behind."""
    assert conversation_category(intent, is_hr=False) == CATEGORY_GENERAL


def test_the_three_categories_are_exhaustive():
    """FR-09's report asserts general + hr_query + hrms_action == total
    messages, which only holds if every turn gets exactly one of the three.
    If this ever returns something else, that invariant breaks silently."""
    seen = {
        conversation_category("apply_leave", is_hr=True),
        conversation_category("policy", is_hr=True),
        conversation_category("non_hr", is_hr=False),
    }
    assert seen == {CATEGORY_GENERAL, CATEGORY_HR_QUERY, CATEGORY_HRMS_ACTION}


@pytest.mark.parametrize("intent", ["payroll", "salary", "performance"])
def test_the_dual_membership_intents_report_as_hrms(intent):
    """These sit in both _DATABASE_CAPABLE_INTENTS and
    _DOCUMENT_BACKED_INTENTS, so "what is the payroll policy" and "what is my
    salary" carry the same intent. Reporting them as HRMS over-reports rather
    than under-reports, which is the safe direction for anything that might
    be read as a permissions signal."""
    assert conversation_category(intent, is_hr=True) == CATEGORY_HRMS_ACTION
