"""Tests for the Assurance by Design standard and its wiring into the assessment generators.

Checks:
- standards/assessment-assurance-design.md exists
- Required section anchors present: the two design questions, Design levers, TILT,
  the five per-category titles, and the by-design self-check
- The standard file contains no em dash or en dash (house style: it is echoed into
  generated output)
- Each of the 7 targeted SKILL.md files references standards/assessment-assurance-design.md
"""

from pathlib import Path

REPO = Path(__file__).resolve().parents[1]
STANDARD = REPO / "standards" / "assessment-assurance-design.md"

STANDARD_PATH_STR = "standards/assessment-assurance-design.md"

TARGET_SKILLS = [
    REPO / "skills" / "quiz-generator" / "SKILL.md",
    REPO / "skills" / "assignment-generator" / "SKILL.md",
    REPO / "skills" / "discussion-generator" / "SKILL.md",
    REPO / "skills" / "rubric-creator" / "SKILL.md",
    REPO / "skills" / "interactive-content" / "SKILL.md",
    REPO / "skills" / "needs-analysis" / "SKILL.md",
    REPO / "skills" / "course-build" / "SKILL.md",
]

CATEGORIES = [
    "Quizzes and Exams",
    "Papers and Written Assignments",
    "Discussions",
    "Projects",
    "Presentations and Oral Assessments",
]


# ---------------------------------------------------------------------------
# Standard file existence and content
# ---------------------------------------------------------------------------

def test_standard_exists():
    assert STANDARD.is_file(), f"standards/assessment-assurance-design.md not found at {STANDARD}"


def test_standard_has_two_design_questions():
    text = STANDARD.read_text(encoding="utf-8")
    assert "Two Design Questions" in text, "standard missing the two design questions section"


def test_standard_has_design_levers():
    text = STANDARD.read_text(encoding="utf-8")
    assert "Design Levers" in text, "standard missing Design Levers section"


def test_standard_has_tilt():
    text = STANDARD.read_text(encoding="utf-8")
    assert "TILT" in text, "standard missing the TILT pairing rule"


def test_standard_has_all_five_categories():
    text = STANDARD.read_text(encoding="utf-8")
    for category in CATEGORIES:
        assert category in text, f"standard missing category: {category!r}"


def test_standard_has_self_check():
    text = STANDARD.read_text(encoding="utf-8")
    assert "Self-Check" in text, "standard missing the by-design self-check section"


def test_standard_no_em_dash():
    text = STANDARD.read_text(encoding="utf-8")
    assert "—" not in text, "standard contains an em dash (—)"


def test_standard_no_en_dash():
    text = STANDARD.read_text(encoding="utf-8")
    assert "–" not in text, "standard contains an en dash (–)"


def test_standard_no_html_em_dash():
    text = STANDARD.read_text(encoding="utf-8")
    assert "&mdash;" not in text, "standard contains &mdash;"


def test_standard_no_html_en_dash():
    text = STANDARD.read_text(encoding="utf-8")
    assert "&ndash;" not in text, "standard contains &ndash;"


# ---------------------------------------------------------------------------
# Wiring into the targeted skills
# ---------------------------------------------------------------------------

def test_targeted_skills_exist():
    for skill_path in TARGET_SKILLS:
        assert skill_path.is_file(), f"expected SKILL.md not found at {skill_path}"


def test_targeted_skills_reference_standard():
    for skill_path in TARGET_SKILLS:
        text = skill_path.read_text(encoding="utf-8")
        assert STANDARD_PATH_STR in text, (
            f"{skill_path} does not reference {STANDARD_PATH_STR}"
        )


# ---------------------------------------------------------------------------
# CLAUDE.md / AGENTS.md carry the clause
# ---------------------------------------------------------------------------

def test_claude_md_has_assurance_by_design_clause():
    text = (REPO / "CLAUDE.md").read_text(encoding="utf-8")
    assert "Assurance by Design" in text, "CLAUDE.md missing the Assurance by Design clause"
    assert STANDARD_PATH_STR in text, "CLAUDE.md does not reference the standard path"


def test_agents_md_has_assurance_by_design_clause():
    text = (REPO / "AGENTS.md").read_text(encoding="utf-8")
    assert "Assurance by Design" in text, "AGENTS.md missing the Assurance by Design clause"
    assert STANDARD_PATH_STR in text, "AGENTS.md does not reference the standard path"


# ---------------------------------------------------------------------------
# Playbook sync comment (no refactor)
# ---------------------------------------------------------------------------

def test_playbook_has_sync_comment():
    text = (REPO / "scripts" / "assessment_design_playbook.py").read_text(encoding="utf-8")
    assert STANDARD_PATH_STR in text, "playbook missing the sync comment referencing the standard"
