from app.message_cleaner import clean_email_reply_text
from app.reply_intent_gate import classify_reply_guardrail


def test_message_cleaner_removes_signature_and_history():
    raw = """Bom dia,\n\nAinda vende os carregadores?\n\nMelhores cumprimentos\nPaulo Costa\nAssistência técnica: aceda aqui\n\nDe: Sérgio Araújo\nAssunto: Campanha"""
    cleaned = clean_email_reply_text(raw)
    assert "Ainda vende os carregadores?" in cleaned
    assert "Assistência técnica" not in cleaned
    assert "De: Sérgio" not in cleaned


def test_guardrail_detects_bounce_but_not_commercial_question():
    assert classify_reply_guardrail({}, "Delivery has failed: Address not found").category == "BOUNCE_EMAIL"
    assert classify_reply_guardrail({}, "Bom dia, ainda vende os carregadores?") is None


def test_guardrail_detects_multilingual_address_update():
    intent = classify_reply_guardrail({}, "My email has changed. Please update your contact to novo@example.com")
    assert intent is not None
    assert intent.category == "ADDRESS_UPDATE"
