"""
Snapshot path helpers.

Resolve committed documentation snapshot paths across local repo checkouts and
production API images. In containers, service modules live under
``/app/src/services`` instead of ``apps/api/src/services``.
"""

from __future__ import annotations

from pathlib import Path


def resolve_repo_root(anchor: Path) -> Path:
    """Resolve the repository root that contains committed docs snapshots."""
    resolved = anchor.resolve()
    start = resolved if resolved.is_dir() else resolved.parent
    for candidate in (start, *start.parents):
        if (candidate / "docs").is_dir():
            return candidate

    container_root = Path("/app")
    if (container_root / "docs").is_dir():
        return container_root

    parents = list(start.parents)
    return parents[2] if len(parents) > 2 else start


def default_evaluations_dir(anchor: Path) -> Path:
    """Resolve the default committed evaluations snapshot directory."""
    return resolve_repo_root(anchor) / "docs" / "evaluations"
