"""Đường dẫn: thư mục chương trình (template) và thư mục dữ liệu người dùng."""
from __future__ import annotations

import os
import sys
from pathlib import Path

APP_DIR_NAME = "NetAutoConfig"


def resource_dir() -> Path:
    """Thư mục chứa file đi kèm chương trình (templates, tasks.yaml)."""
    if getattr(sys, "frozen", False):  # chạy từ file .exe (PyInstaller)
        return Path(getattr(sys, "_MEIPASS", Path(sys.executable).parent))
    return Path(__file__).resolve().parent.parent


def data_dir() -> Path:
    """Thư mục dữ liệu (DB, backup, log). Đổi bằng biến môi trường NETAUTO_HOME."""
    env = os.environ.get("NETAUTO_HOME")
    base = Path(env) if env else Path.home() / APP_DIR_NAME
    for sub in ("", "backups", "logs", "custom_templates", "reports"):
        (base / sub).mkdir(parents=True, exist_ok=True)
    return base
