from pathlib import Path

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


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


def test_mark_no_interest_is_available_action():
    catalog = read("app/action_catalog.py")
    prompt = read("app/action_prompt.py")
    task_service = read("app/task_service.py")
    admin = read("app/admin_dashboard.py")

    assert '"MARK_NO_INTEREST"' in catalog
    assert '"action": "Marcar sem interesse"' in catalog
    assert "não tem veículos elétricos" in prompt
    assert '"MARK_NO_INTEREST": ("vendas", "Marcar sem interesse")' in task_service
    assert '"MARK_NO_INTEREST": "Marcar sem interesse"' in admin


def test_mark_no_interest_has_deterministic_rule():
    decider = read("app/action_decider.py")
    assert "detect_deterministic_action" in decider
    assert "MARK_NO_INTEREST" in decider
    assert "não temos" in decider or "n[aã]o" in decider
    assert "deterministic-rule" in decider


def test_no_interest_closes_existing_opportunity_only_when_task_done():
    opp = read("app/opportunity_service.py")
    assert '"MARK_NO_INTEREST",' in opp
    assert '"MARK_NO_INTEREST": "REVIEW"' in opp
    assert '"MARK_NO_INTEREST": "NO_INTEREST"' in opp
    assert 'if action_code == "MARK_NO_INTEREST" and not existing' in opp
