"""Documentation validation for Loyalty Phase 7.0."""
from pathlib import Path


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


def test_phase_docs_exist():
    assert (ROOT / "docs" / "loyalty-phase-7-0.md").exists()
    assert (ROOT / "docs" / "loyalty-phase-7-0-audit.md").exists()
    assert (ROOT / "docs" / "loyalty-phase-7-1.md").exists()
    assert (ROOT / "docs" / "phase-handover" / "phase-7-1.md").exists()
    assert (ROOT / "docs" / "phases" / "Loyalty" / "README.md").exists()
    assert (ROOT / "docs" / "architecture" / "adr" / "ADR-011.md").exists()


def test_module_registry_mentions_loyalty():
    text = (ROOT / "docs" / "module-registry.md").read_text(encoding="utf-8")
    assert "## loyalty" in text.lower()
    assert "loyalty_db" in text
    assert "loyalty." in text
    assert "7.1" in text or "0.7.1" in text


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


def test_service_readme_documents_boundaries():
    text = (ROOT / "backend" / "services" / "loyalty" / "README.md").read_text(
        encoding="utf-8"
    )
    assert "loyalty_db" in text
    assert "CRM" in text or "crm" in text.lower()
    assert "balance" in text.lower() or "ledger" in text.lower()
