from __future__ import annotations
import sys
from pathlib import Path

def get_app_root() -> Path:
    if getattr(sys, "frozen", False):
        return Path(sys.executable).resolve().parent
    return Path(__file__).resolve().parents[1]

def get_data_dir() -> Path:
    return get_app_root() / "data"

def ensure_dirs() -> dict[str, Path]:
    root = get_app_root()
    data_dir = root / "data"
    db_dir = data_dir / "db"
    docs_dir = data_dir / "docs"
    media_dir = data_dir / "media"
    backups_dir = data_dir / "backups"
    license_dir = data_dir / "license"

    for d in (data_dir, db_dir, docs_dir, media_dir, backups_dir, license_dir):
        d.mkdir(parents=True, exist_ok=True)

    (media_dir / "voice_actors").mkdir(parents=True, exist_ok=True)

    return {
        "root": root,
        "data": data_dir,
        "db": db_dir,
        "docs": docs_dir,
        "media": media_dir,
        "backups": backups_dir,
        "license": license_dir,
    }
