from typing import Any, Callable

from ._Parser import Parser


class FunctionParser(Parser):
    """Adapter that allows using a callable as a Parser."""

    def __init__(self, fn: Callable[[dict, str], Any]):
        """Args:
        fn: Callable that receives (data: dict, event_type: str) and returns the request object.
        """
        self._fn = fn

    def parse(self, data: dict, event_type: str) -> Any:
        return self._fn(data, event_type)
