from pathlib import Path


def read(path: str) -> str:
    return Path(path).read_text(encoding="utf-8")


def test_llm_first_mode_is_configured():
    config = read("app/config.py")
    assistant = read("app/reply_assistant_service.py")
    templates = read("app/message_templates.py")
    assert "clientflow_reply_llm_first_enabled" in config
    assert "_llm_first_enabled" in assistant
    assert "classify_reply_guardrail" in assistant
    assert "LLM_BUSINESS_REPLY" in templates


def test_guardrails_are_separate_from_broad_intent_gate():
    gate = read("app/reply_intent_gate.py")
    assert "def classify_reply_guardrail" in gate
    assert "AUTO_REPLY_PATTERNS" in gate
    assert "BOUNCE_EMAIL" in gate
    assert "UNSUBSCRIBE_REQUEST" in gate
    assert "ADDRESS_UPDATE" in gate


def test_message_cleaner_used_before_llm():
    cleaner = read("app/message_cleaner.py")
    llm = read("app/llm_reply_generator.py")
    assistant = read("app/reply_assistant_service.py")
    assert "extract_customer_reply_text" in cleaner
    assert "extract_customer_reply_text(task)" in llm
    assert "extract_customer_reply_text(task)" in assistant


def test_audit_surfaces_llm_interpretation():
    script = read("scripts/audit_task_reply_suggestions.py")
    assert "llm_intent" in script
    assert "llm_customer_need" in script
    assert "Necessidade detetada pelo LLM" in script
