from __future__ import annotations

import tomllib
from dataclasses import dataclass
from pathlib import Path

from .util import project_root


@dataclass(frozen=True)
class EvaluationProfile:
    backend: str
    model: str
    reasoning_effort: str
    timeout_seconds: int
    max_repair_attempts: int
    previous_context_characters: int
    next_context_characters: int
    max_batch_pages: int
    max_infrastructure_retries: int = 2
    infrastructure_backoff_seconds: float = 5.0


def load_profile(path: Path | None = None) -> EvaluationProfile:
    target = path or project_root() / "config" / "evaluation-profile.toml"
    with target.open("rb") as stream:
        values = tomllib.load(stream)
    return EvaluationProfile(**values)
