from abc import ABC, abstractmethod
from fastapi import FastAPI
from starlette.middleware.base import BaseHTTPMiddleware
from typing import List


class Controller(ABC):
    def __init__(
        self,
        path: str,
        method: str,
        middlewares: List[BaseHTTPMiddleware] = []
    ):
        self.__app = FastAPI()
        self.__path = path
        self.__method = method
        self.__middlewares = middlewares

        for middleware in self.__middlewares:
            self.app.add_middleware(middleware)

        self.app.api_route(
            path=self.__path,
            methods=[self.__method]
        )(self.handle)

    @property
    def app(self):
        return self.__app

    @abstractmethod
    async def handle(**kwargs):
        raise NotImplemented
