from pathlib import Path


def test_reconciliation_decision_service_exists_and_is_read_only():
    text = Path("app/reconciliation_decision_service.py").read_text()
    assert "classify_reconciliation_item" in text
    assert "classify_reconciliation_process" in text
    assert "reconciliation_decision_summary" in text
    assert "CREATE UNIQUE INDEX" not in text


def test_reconciliation_page_exposes_decision_lanes_and_actions():
    text = Path("app/admin_ui/pages/reconciliation.py").read_text()
    assert "cf-reconcile-decision-grid" in text
    assert "Ação recomendada" in text
    assert "/reconciliation/{item_id}/needs-review" in text
    assert "/reconciliation/processes/ignore" in text
    assert "sort_items_for_operator" in text


def test_opportunity_page_has_operational_map():
    text = Path("app/admin_ui/pages/opportunities.py").read_text()
    assert "Mapa operacional" in text
    assert "Cliente fiscal" in text
    assert "Documento principal" in text
    assert "Ações avançadas" in text


def test_jasmin_actions_avoid_duplicate_linking_when_current_doc_exists():
    text = Path("app/admin_dashboard.py").read_text()
    assert "Já existe documento atual. A associação direta fica bloqueada" in text
    assert "invoice_source_exists" in text
    assert "É necessário um orçamento ou pró-forma atual para converter" in text
