"""Documentation validation for CRM phases."""
from pathlib import Path


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


def test_phase_docs_exist():
    assert (ROOT / "docs" / "crm-phase-6-0.md").exists()
    assert (ROOT / "docs" / "crm-phase-6-1.md").exists()
    assert (ROOT / "docs" / "crm-phase-6-2.md").exists()
    assert (ROOT / "docs" / "crm-phase-6-3.md").exists()


def test_module_registry_mentions_crm_active_or_foundation():
    text = (ROOT / "docs" / "module-registry.md").read_text(encoding="utf-8")
    assert "## crm" in text.lower() or "| CRM |" in text or "## crm" in text
    assert "crm_db" in text
    assert "crm." in text
    assert "6.3" in text or "0.6.3" in text


def test_progress_mentions_phase_6_3():
    text = (ROOT / "docs" / "progress.md").read_text(encoding="utf-8")
    assert "6.3" in text


def test_service_readme_documents_boundaries():
    text = (ROOT / "backend" / "services" / "crm" / "README.md").read_text(
        encoding="utf-8"
    )
    assert "Lead" in text or "lead" in text.lower()
    assert "crm_db" in text
    assert "Automation" in text or "automation" in text.lower()
