"""Eval harness config: fixture vs user-provided repo path, artifact output."""

from __future__ import annotations

import os
from dataclasses import dataclass
from pathlib import Path


@dataclass(frozen=True, slots=True)
class EvalConfig:
    """Configuration for CODE_QA evaluation runs."""

    repo_path: Path
    test_results_dir: Path
    golden_cases_path: Path
    project_id: str | None = None
    use_fixture: bool = True

    @classmethod
    def from_env(cls, project_root: Path | None = None) -> "EvalConfig":
        """Build config: fixture repo by default; optional CODE_QA_REPO_PATH for local calibration."""
        root = project_root or Path(__file__).resolve().parent.parent
        raw_repo = os.getenv("CODE_QA_REPO_PATH", "").strip()
        if raw_repo:
            repo_path = Path(raw_repo).expanduser().resolve()
            use_fixture = False
            project_id = os.getenv("CODE_QA_PROJECT_ID", "").strip() or repo_path.name
        else:
            repo_path = root / "fixtures" / "code_qa_repo"
            use_fixture = True
            project_id = "code_qa_repo"
        test_results_dir = root / "test_results" / "code_qa_eval"
        golden_cases_path = root / "golden" / "code_qa" / "cases.yaml"
        return cls(
            repo_path=repo_path,
            test_results_dir=test_results_dir,
            golden_cases_path=golden_cases_path,
            project_id=project_id,
            use_fixture=use_fixture,
        )
