from typing import Any

from maxapi.filters.filter import BaseFilter
from maxapi.types.updates.message_callback import MessageCallback


class PayloadStartsWith(BaseFilter):
    """Фильтр callback-событий по префиксу payload."""

    def __init__(self, prefix: str) -> None:
        self.prefix = prefix

    async def __call__(self, event: Any) -> bool:
        if not isinstance(event, MessageCallback):
            return False
        payload = event.callback.payload or ""
        return payload.startswith(self.prefix)
