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_v495_reconciliation_service_suggests_open_operations():
    service = read("app/reconciliation_service.py")

    assert "find_open_operation_suggestions_for_reconciliation" in service
    assert "operation_suggestions" in service
    assert "operação aberta" in service
    assert "match_score" in service
    assert "status = 'pending'" in service
    assert "o.status = 'open'" in service


def test_v495_reconciliation_ui_prefills_link_actions_from_suggestions():
    page = read("app/admin_ui/pages/reconciliation.py")

    assert "Sugestão encontrada em Operations" in page
    assert "Ligar a esta operação" in page
    assert "name=\"opportunity_id\"" in page
    assert "Escolher outra oportunidade" in page
    assert "Criar oportunidade" in page


def test_v495_reconciliation_suggestion_styles_exist():
    styles = read("app/admin_ui/styles.py")

    assert ".cf-reconcile-suggestion" in styles
    assert "v4.9.5 reconciliation operation suggestions" in styles
