from __future__ import annotations

from typing import Callable


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

    def register(self, action_type: str, handler: Callable) -> ActionRegistry:
        self._handlers[action_type] = handler
        return self

    def dispatch(self, action: dict):
        action_type = action.get("type")
        handler = self._handlers.get(action_type)
        if handler is None:
            return None
        payload = action.get("payload", {})
        return handler(payload)

    def dispatch_all(self, actions: list[dict]) -> list:
        return [self.dispatch(action) for action in actions]

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

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