"""Documentation validation for Experience Phase 11.10."""
from pathlib import Path

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


def _read(rel: str) -> str:
    return (ROOT / rel).read_text(encoding="utf-8")


def test_phase_docs_exist_and_mention_db():
    text = _read("docs/experience-phase-11-10.md")
    assert "experience_db" in text
    assert "11.10" in text
    assert "Torbat Pages" in text
    assert "analytics" in text.lower()
    assert "ai content" in text.lower() or "ai_content" in text.lower()


def test_handover_exists():
    text = _read("docs/phase-handover/phase-11-10.md")
    assert "experience" in text.lower()
    assert "experience_db" in text
    assert "11.10" in text


def test_audit_report_exists():
    text = _read("docs/experience-phase-11-10-audit.md")
    assert "11.10" in text
    assert "Pass" in text


def test_module_registry_updated():
    text = _read("docs/module-registry.md")
    assert "experience" in text.lower()
    assert "experience_db" in text
    assert "0.11.10.0" in text or "11.10" in text


def test_service_readme():
    text = _read("backend/services/experience/README.md")
    assert "experience_db" in text
    assert "8008" in text
    assert "analytics" in text.lower()


def test_adr_016_exists():
    text = _read("docs/architecture/adr/ADR-016.md")
    assert "Experience" in text
    assert "experience_db" in text


def test_previous_phase_docs_still_present():
    text = _read("docs/experience-phase-11-9.md")
    assert "11.9" in text
    assert "widget" in text.lower()
