from __future__ import annotations

from core.commands.base import CommandHandler

_HANDLERS: dict[str, CommandHandler] = {}


def register(handler: CommandHandler):
    slug = str(getattr(handler, "slug", "") or "").strip().lower()
    if not slug:
        raise ValueError("handler slug is required")
    _HANDLERS[slug] = handler


def get(slug: str) -> CommandHandler | None:
    return _HANDLERS.get(str(slug or "").strip().lower())
