from pathlib import Path


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


def test_reply_intent_gate_exists_and_blocks_commercial_fallbacks():
    gate = read("app/reply_intent_gate.py")
    assistant = read("app/reply_assistant_service.py")
    templates = read("app/message_templates.py")
    assert "classify_reply_intent" in gate
    assert "BOUNCE_EMAIL" in gate
    assert "UNSUBSCRIBE_REQUEST" in gate
    assert "NO_INTEREST" in gate
    assert "SUPPORT_INCIDENT" in gate
    assert "MANUAL_REVIEW" in gate
    assert "classify_reply_intent" in assistant
    assert "intent_gate" in assistant
    assert "MANUAL_REVIEW_REQUIRED" in templates
    assert '"SEND_INFO": "MANUAL_REVIEW_REQUIRED"' in templates


def test_non_sales_templates_exist():
    templates = read("app/message_templates.py")
    for code in [
        "INTERNAL_BOUNCE_EMAIL",
        "ACK_UNSUBSCRIBE",
        "ACK_ADDRESS_UPDATE",
        "ACK_NO_INTEREST",
        "ACK_SUPPORT_RECEIVED",
        "ACK_CALLBACK_REQUEST",
    ]:
        assert code in templates
    assert 'reply_type="no_customer_reply"' in templates
    assert 'reply_type="support_ack"' in templates


def test_audit_report_surfaces_intent_gate():
    script = read("scripts/audit_task_reply_suggestions.py")
    assert "intent_category" in script
    assert "intent_counts" in script
    assert "Intent gate" in script
    assert "Motivo da triagem" in script
