from __future__ import annotations

from pathlib import Path


BASE_DIR = Path(__file__).resolve().parent.parent.parent
THEMES_DIR = BASE_DIR / 'themes'

SESSION_DIR = BASE_DIR / 'session'
CONFIG_PATH = SESSION_DIR / 'config.json'
CHAR_PATH = SESSION_DIR / 'character.md'
WORLD_PATH = SESSION_DIR / 'world.md'
BOOK_PATH = SESSION_DIR / 'book.md'
JOURNAL_PATH = SESSION_DIR / 'journal.md'
AMBIENCE_PATH = SESSION_DIR / 'ambience.md'
LOG_PATH = SESSION_DIR / 'session_log.md'
LLM_LOG_PATH = SESSION_DIR / 'llm.log'
AMBIENCE_OPTIONS_PATH = SESSION_DIR / "ambience_options.md"
CHANGES_PATH = SESSION_DIR / "changes.md"
RULES_INJECTION_PATH = SESSION_DIR / "rules_injection.md"
META_LOG_PATH = SESSION_DIR / "meta_log.md"
AUDIO_DIR = SESSION_DIR / "audio"
ACTIVE_THEME_PATH = SESSION_DIR / "current_theme"

ARCHIVE_DIR = BASE_DIR / 'archive'


def get_active_theme_id() -> str:
    if ACTIVE_THEME_PATH.exists():
        return ACTIVE_THEME_PATH.read_text().strip() or "default"
    return "default"


def get_theme_dir(theme_id: str | None = None) -> Path:
    return THEMES_DIR / (theme_id or get_active_theme_id())


def get_rules_dir(theme_id: str | None = None) -> Path:
    return get_theme_dir(theme_id) / "rules"


def get_core_rules_path(theme_id: str | None = None) -> Path:
    return get_rules_dir(theme_id) / "core_mechanics.md"


def get_mechanics_path(theme_id: str | None = None) -> Path:
    return get_rules_dir(theme_id) / "mechanics.md"


def get_character_creation_path(theme_id: str | None = None) -> Path:
    return get_rules_dir(theme_id) / "character_creation.md"


def get_end_game_path(theme_id: str | None = None) -> Path:
    return get_rules_dir(theme_id) / "end_game.md"


def get_character_template_path(theme_id: str | None = None) -> Path:
    return get_theme_dir(theme_id) / "character_template.md"


def get_theme_audio_dir(theme_id: str | None = None) -> Path:
    return get_theme_dir(theme_id) / "audio"


def get_theme_ambience_options_path(theme_id: str | None = None) -> Path:
    return get_theme_dir(theme_id) / "ambience_options.md"
