from pathlib import Path


def test_archive_spam_is_not_lost_and_excluded_from_funnel():
    service = Path('app/opportunity_service.py').read_text()
    assert 'def archive_spam_opportunity_if_safe' in service
    assert "stage = 'ARCHIVED'" in service
    assert "status = 'archived'" in service
    assert "'exclude_from_funnel', True" in service or '"exclude_from_funnel": True' in service
    assert 'has_commercial_or_external_evidence' in service


def test_task_spam_reclassification_archives_safe_opportunity():
    task_service = Path('app/task_service.py').read_text()
    assert 'new_action_code == "IGNORE_SPAM"' in task_service
    assert 'archive_spam_opportunity_if_safe' in task_service
    assert 'auto_archive_result' in task_service


def test_ui_exposes_archive_spam_action_not_lost():
    opportunities = Path('app/admin_ui/pages/opportunities.py').read_text()
    assert '/archive-spam' in opportunities
    assert 'Arquivar spam/falso positivo' in opportunities
    assert 'sem contar como perdida' in opportunities


def test_cascading_followups_from_114_remain_available():
    followups = Path('app/followup_service.py').read_text()
    assert 'FOLLOW_UP_CASCADE_BY_ACTION' in followups
    assert 'FOLLOW_UP_CUSTOMER_REVIEW' in followups
    assert 'follow_up_stage' in followups
    assert 'max_stage' in followups


def test_archived_not_rendered_on_open_board_even_status_all():
    opportunities = Path('app/admin_ui/pages/opportunities.py').read_text()
    assert 'column[0] not in {"closed", "archived"}' in opportunities
    assert 'key in {"closed", "archived"}' in opportunities
