"""Common protocols used by handler implementations."""

from __future__ import annotations

from typing import Protocol, TypeVar, runtime_checkable

from aws_lambda_typing.events import APIGatewayProxyEventV1
from aws_lambda_typing.responses import APIGatewayProxyResponseV1

EventT = TypeVar("EventT", contravariant=True)
RequestT = TypeVar("RequestT", contravariant=True)
ResponseT = TypeVar("ResponseT", covariant=True)


@runtime_checkable
class IPolicyHandler(Protocol[RequestT, ResponseT]):
    def handle(self, event: RequestT) -> ResponseT: ...
    def can_handle(self, event: RequestT) -> bool: ...


@runtime_checkable
class IRestHandler(Protocol[EventT, ResponseT]):
    def handle(self, event: EventT) -> ResponseT: ...
    def can_handle(self, event: EventT) -> bool: ...


@runtime_checkable
class IJwtTokenHandler(Protocol):
    def __call__(self, event: APIGatewayProxyEventV1) -> None: ...


@runtime_checkable
class ICorsHandler(Protocol):
    def apply(
        self,
        event: APIGatewayProxyEventV1,
        response: APIGatewayProxyResponseV1,
    ) -> APIGatewayProxyResponseV1: ...


__all__ = ["ICorsHandler", "IJwtTokenHandler", "IPolicyHandler", "IRestHandler"]

