"""Central configuration for CSS Mod Manager.

Defines all filesystem paths used by the application (server root, repository,
UMC files, backups, temp/upload folders) as well as the static option schemas
(`CATEGORY_OPTIONS`, `MAP_OPTIONS`) used by the validator to check UMC entries.

Importing this module also ensures the required data directories exist on disk.
"""

from pathlib import Path

# .parent (core) -> .parent (css_mod_manager) -> .parent (Dossier racine serveur)
SERVER_ROOT = Path(__file__).resolve().parent.parent.parent

# .parent (core) -> .parent (css_mod_manager) -> .parent (Dossier racine serveur)
BASE_DIR = Path(__file__).resolve().parent.parent.parent
PROJECT_ROOT = Path(__file__).resolve().parent.parent
CSTRIKE_ROOT = PROJECT_ROOT.parent / "cstrike"

# ==================================================
# PATHS
# ==================================================

# Configs
SERVER_CSTRIKE = SERVER_ROOT / "cstrike"
APP_DIR = SERVER_ROOT / "CSS_Mod_Manager"
REPOSITORY = APP_DIR / "repository"
CONFIG_FILE = APP_DIR / "config.json"
DEPLOY_MANIFEST = APP_DIR / "deployed_files.json"

# Maps
UMC_FILE = CSTRIKE_ROOT / "umc_mapcycle.txt"
UMC_MASTER_FILE = PROJECT_ROOT / "umc_mapcycle_master.txt"
MAPS_FOLDER = CSTRIKE_ROOT / "download" / "maps"
DOWNLOAD_MAPS_FOLDER = CSTRIKE_ROOT / "download" / "maps"
BACKUP_FOLDER = PROJECT_ROOT / "data" / "backups"
TEMP_FOLDER = PROJECT_ROOT / "data" / "temp"
UPLOAD_FOLDER = PROJECT_ROOT / "uploads"
DATA_FOLDER = PROJECT_ROOT / "data"
LOG_FOLDER = DATA_FOLDER / "logs"

# ==================================================
# UMC OPTIONS
# ==================================================
CATEGORY_OPTIONS = {
    "command": "string",
    "display": "string",
    "default_min_players": "integer",
    "default_max_players": "integer",
    "maps_invote": "integer",
    "group_weight": "integer",
    "exclude": "integer",
}

MAP_OPTIONS = {
    "display": "string",
    "command": "string",
    "weight": "integer",
    "min_players": "integer",
    "max_players": "integer",
    "tier": "integer",
    "target_mods": "string",
}

PERMANENT_CATEGORIES = ["normal"]

CATEGORY_OPTION_KEYS = sorted(CATEGORY_OPTIONS.keys())
MAP_OPTION_KEYS = sorted(MAP_OPTIONS.keys())
OPTION_TYPES = {**CATEGORY_OPTIONS, **MAP_OPTIONS}

TARGET_MOD = {
    "CSSCSGO._AbNeR_DeathRun_Manager_v2.6fix": "DeathRun",
    "awp_restricted_sdf": "awp restricted",
    "C&R": "cops and runners",
    "bhoptimer-v4.0.1": "bhop",
    "Only Headshot_1.4": "headshot",
}
# ==================================================
# Advance Parameters
# ==================================================
MAX_BACKUPS = 50
DELETE_TEMP_BSP_AFTER_INSTALL = False

for folder in [DATA_FOLDER, TEMP_FOLDER, BACKUP_FOLDER, LOG_FOLDER, UPLOAD_FOLDER]:
    folder.mkdir(parents=True, exist_ok=True)
