"""Game State Integration adapters.

Each game gets one module in this package. A module is an adapter when it
defines:

    GAME   = "cs2"                # url slug: POST /api/gsi/<GAME>
    LABEL  = "Counter-Strike 2"   # display name
    parse(payload: dict, state: dict) -> list[dict]
        # Called per POST from the game. `state` is a per-session dict the
        # adapter mutates to diff snapshot-style payloads. Returns normalized
        # events: {"type": str, "title": str, "detail": dict}.

Optional (drives the one-click setup download in the admin panel):
    CONFIG_FILENAME = "gamestate_integration_product.cfg"
    CONFIG_HINT     = "where to put the file"
    config_text(url: str, token: str) -> str

Games with no adapter module still work: POST pre-normalized events
({"type","title","detail"} or {"events":[...]}) to /api/gsi/<anything>
with the X-GSI-Token header. Adding a bespoke adapter later (Deadlock,
someday) is just a new file here — it is discovered automatically.
"""
import importlib
import pkgutil

_ADAPTERS = None


def adapters() -> dict:
    global _ADAPTERS
    if _ADAPTERS is None:
        _ADAPTERS = {}
        for m in pkgutil.iter_modules(__path__):
            if m.name.startswith("_"):
                continue
            mod = importlib.import_module(f"{__name__}.{m.name}")
            if hasattr(mod, "GAME") and callable(getattr(mod, "parse", None)):
                _ADAPTERS[mod.GAME] = mod
    return _ADAPTERS
