from __future__ import annotations

from typing import Callable


class EventRegistry:
    def __init__(self):
        self._handlers: dict[str, list[Callable]] = {}

    def on(self, event_type: str, handler: Callable) -> EventRegistry:
        self._handlers.setdefault(event_type, []).append(handler)
        return self

    def dispatch(self, payload: dict) -> bool:
        event_type = payload.get("event")
        data = payload.get("data", payload)
        handlers = self._handlers.get(event_type)
        if not handlers:
            return False
        for handler in handlers:
            handler(data)
        return True

    def is_registered(self, event_type: str) -> bool:
        return event_type in self._handlers

    @property
    def event_types(self) -> list[str]:
        return list(self._handlers.keys())
