from __future__ import annotations

from functools import lru_cache
from pathlib import Path


@lru_cache(maxsize=1)
def get_root_path() -> Path:
    """返回项目根目录：从 utils/path.py 回退到仓库根 (../../..)。"""
    return Path(__file__).resolve().parents[4]


@lru_cache(maxsize=1)
def get_apps_path() -> Path:
    """返回 apps 目录路径。"""
    return get_root_path() / "apps"


@lru_cache(maxsize=1)
def get_jingrow_root() -> Path:
    """返回 jingrow 模块根目录路径：apps/jingrow/jingrow"""
    return get_root_path() / "apps" / "jingrow" / "jingrow"


@lru_cache(maxsize=1)
def get_files_dir() -> Path:
    """返回文件存储目录：apps/jingrow/jingrow/public/files"""
    files_dir = get_jingrow_root() / "public" / "files"
    files_dir.mkdir(parents=True, exist_ok=True)
    return files_dir

