import json
from pathlib import Path
from typing import Any

_PROMPTS_DIR = Path(__file__).parent


class PromptManager:
    _instance = None
    _data: dict[str, Any] = {}

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
            cls._instance._load_all()
        return cls._instance

    def _load_all(self):
        for json_file in _PROMPTS_DIR.glob("*.json"):
            key = json_file.stem
            with open(json_file, "r", encoding="utf-8") as f:
                self._data[key] = json.load(f)

    def get(self, key: str, default: Any = None) -> Any:
        return self._data.get(key, default)


_prompts = PromptManager()


def get_system_prompt_template() -> str:
    return _prompts.get("system_prompt", {}).get("template", "")


def get_language_guidance_map() -> dict[str, str]:
    return _prompts.get("language_guidance", {})


def get_inline_examples() -> str:
    return _prompts.get("inline_examples", {}).get("content", "")


def get_system_prompt_pro_template() -> str:
    return _prompts.get("system_prompt_pro", {}).get("template", "")


def get_inline_examples_pro() -> str:
    return _prompts.get("inline_examples_pro", {}).get("content", "")


def get_vlm_ocr_prompt() -> str:
    return _prompts.get("vlm_ocr", {}).get("prompt", "")
