import json
from pathlib import Path

FIXTURES_DIR = Path(__file__).parent / "fixtures"


def _fixture_json(name: str):
    path = FIXTURES_DIR / name
    return json.loads(path.read_text(encoding="utf-8"))


def _sample_citations():
    return [
        {
            "stage": "mel",
            "citation_type": "rag_result",
            "namespace": "usaid_ads201",
            "source": "/tmp/usaid_guide.pdf",
            "page": 12,
            "chunk": 3,
            "chunk_id": "usaid_ads201_p12_c0",
            "used_for": "EG.3.2-1",
            "label": "USAID ADS 201 p.12",
            "excerpt": "Official indicator guidance excerpt",
            "citation_confidence": 0.82,
            "result_level": "outcome",
            "statement_path": "toc.development_objectives[0].description",
            "evidence_signal": "PMP and indicator reference evidence",
            "review_hint": "Use this citation to support the indicator row in the USAID monitoring package.",
        },
        {
            "stage": "architect",
            "citation_type": "strategy_reference",
            "namespace": "usaid_ads201",
            "source": "strategy::usaid",
            "page": "",
            "chunk": "",
            "chunk_id": "strategy::usaid::toc",
            "used_for": "toc_claim",
            "label": "Strategy reference",
            "excerpt": "",
            "citation_confidence": 0.75,
            "result_level": "general",
            "statement_path": "toc.project_goal",
            "evidence_signal": "strategy guidance only",
            "review_hint": "Use as strategy context only; replace with grounded evidence before external review.",
        },
    ]


def _sample_critic_findings():
    return [
        {
            "finding_id": "finding-123",
            "status": "acknowledged",
            "severity": "high",
            "section": "toc",
            "code": "TOC_SCHEMA_INVALID",
            "review_title": "ToC Schema Invalid",
            "review_bucket": "compliance",
            "triage_priority": "high",
            "message": "ToC schema contract mismatch.",
            "recommended_action": "Revise the ToC so it matches the donor review package before the next export.",
            "reviewer_next_step": "ToC Schema Invalid: Revise the ToC so it matches the donor review package before the next export.",
            "fix_hint": "Revise objective structure.",
            "version_id": "toc_v2",
            "source": "rules",
        }
    ]


def _sample_review_comments():
    return [
        {
            "comment_id": "comment-123",
            "status": "resolved",
            "section": "toc",
            "author": "reviewer-1",
            "message": "Adjusted objective wording and assumptions.",
            "version_id": "toc_v2",
            "linked_finding_id": "finding-123",
            "ts": "2026-02-25T10:00:00Z",
        }
    ]


def _sample_quality_summary():
    return {
        "quality_score": 8.5,
        "critic_score": 8.0,
        "needs_revision": False,
        "engine": "rules+llm",
        "rule_score": 8.0,
        "llm_score": 8.5,
        "fatal_flaw_count": 1,
        "citation_count": 4,
    }
