"""Load golden cases from YAML for CODE_QA evaluation."""

from __future__ import annotations

from dataclasses import dataclass, field
from pathlib import Path
from typing import Any

import yaml


@dataclass(slots=True)
class GoldenCase:
    """Single golden case for pipeline evaluation."""

    id: str
    query: str
    expected_intent: str
    expected_sub_intent: str
    expected_answer_mode: str = "normal"
    expected_target_hint: str | None = None
    expected_path_scope_contains: list[str] = field(default_factory=list)
    expected_symbol_candidates_contain: list[str] = field(default_factory=list)
    expected_layers: list[str] = field(default_factory=list)
    notes: str = ""


def load_golden_cases(path: Path) -> list[GoldenCase]:
    """Load and parse golden cases from YAML. Returns list of GoldenCase."""
    if not path.exists():
        return []
    with path.open(encoding="utf-8") as f:
        data = yaml.safe_load(f) or {}
    cases_raw = data.get("cases") or []
    out: list[GoldenCase] = []
    for c in cases_raw:
        if not isinstance(c, dict) or not c.get("id") or not c.get("query"):
            continue
        out.append(GoldenCase(
            id=str(c["id"]),
            query=str(c["query"]),
            expected_intent=str(c.get("expected_intent", "CODE_QA")),
            expected_sub_intent=str(c.get("expected_sub_intent", "EXPLAIN")),
            expected_answer_mode=str(c.get("expected_answer_mode", "normal")),
            expected_target_hint=c.get("expected_target_hint"),
            expected_path_scope_contains=list(c.get("expected_path_scope_contains") or []),
            expected_symbol_candidates_contain=list(c.get("expected_symbol_candidates_contain") or []),
            expected_layers=list(c.get("expected_layers") or []),
            notes=str(c.get("notes") or ""),
        ))
    return out
