"""Path helpers for g-gremlin runtime/config data."""

from __future__ import annotations

import os
from functools import lru_cache
from pathlib import Path


@lru_cache(maxsize=1)
def resolve_gremlin_home() -> Path:
    """Resolve the g-gremlin home directory from env or default location."""
    env = os.environ.get("G_GREMLIN_HOME", "").strip()
    if env:
        expanded = os.path.expanduser(os.path.expandvars(env))
        return Path(expanded).resolve()
    return Path.home() / ".g_gremlin"


def gremlin_path(*parts: str) -> Path:
    """Join one or more path parts under the resolved g-gremlin home."""
    return resolve_gremlin_home().joinpath(*parts)


__all__ = ["resolve_gremlin_home", "gremlin_path"]
