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

    assert "PROCESS_STEP_BY_EXTERNAL_TYPE" in service
    assert "list_reconciliation_process_candidates" in service
    assert "infer_reconciliation_process_state" in service
    assert "create_opportunity_from_reconciliation_process" in service
    assert "link_reconciliation_process_to_opportunity" in service
    assert "opportunity_reconstructed_from_reconciliation" in service
    assert "reconciliation_evidence_imported" in service


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

    assert "Processos candidatos" in page
    assert "_render_process_candidates" in page
    assert "Criar oportunidade reconstruída" in page
    assert "Ligar processo à sugestão" in page
    assert 'action="/reconciliation/processes/create-opportunity"' in page
    assert 'action="/reconciliation/processes/link"' in page


def test_v499_reconciliation_styles_and_docs_exist():
    styles = read("app/admin_ui/styles.py")
    docs = read("docs/CLIENTFLOW_V499_PROCESS_TIMELINE_RECONSTRUCTION.md")

    assert "v4.9.9 process timeline reconstruction" in styles
    assert "cf-reconcile-process-card" in styles
    assert "Process Timeline Reconstruction" in docs
