from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def test_central_rules_suggest_close_instead_of_tracking_followup():
    rules = (ROOT / "app/domain/opportunity_flow/rules.py").read_text(encoding="utf-8")
    assert "ACTION_CLOSE_OPPORTUNITY" in rules
    assert "por agora não criar follow-up de tracking/entrega" in rules
    assert "Confirmar tracking/entrega ao cliente" not in rules
    assert "Concluir a oportunidade" in rules


def test_workflow_guard_closes_when_physical_closed_paid_and_invoiced():
    guard = (ROOT / "app/workflow_guard.py").read_text(encoding="utf-8")
    assert "def _physical_closed" in guard
    assert "physical_closed and payment and invoice" in guard
    assert '"action_key": "delivered"' in guard
    assert '"label": "Concluir oportunidade"' in guard
    assert "não criar follow-up de tracking/entrega" in guard
    assert "Odoo indica picking/entrega concluído; falta confirmar pagamento pós-entrega" in guard


def test_close_action_label_exists_in_profiles():
    for rel in ["config/company_profiles/blif/labels.yaml", "config/company_profiles/default/labels.yaml"]:
        text = (ROOT / rel).read_text(encoding="utf-8")
        assert "CLOSE_OPPORTUNITY:" in text
        assert "label: Concluir oportunidade" in text
