from typing import Optional
from jingrow.config import Config

_adapter = None

def init_adapter(run_mode: str = "api"):
    global _adapter
    if run_mode == "api":
        from jingrow.core.adapters.api_adapter import ApiAdapter
        _adapter = ApiAdapter()
    elif run_mode == "local":
        from jingrow.core.adapters.local_adapter import LocalAdapter
        _adapter = LocalAdapter()
    else:
        raise ValueError(f"Unsupported run_mode: {run_mode}. Supported modes: 'api', 'local'")

def get_adapter():
    global _adapter
    if _adapter is None:
        # Lazy init using Config if not explicitly initialized
        init_adapter(getattr(Config, "run_mode", "api"))
    return _adapter


