from typing import Annotated

import inject
from litestar import (
    Controller,
    post,
)
from litestar.datastructures import UploadFile
from litestar.enums import RequestEncodingType
from litestar.params import Body

from server.modules.recognizer import RecognizerService


class BreedsController(Controller):
    path = "/beerds"

    @post("/dogs")
    async def beerds_dogs(self, data: Annotated[UploadFile, Body(media_type=RequestEncodingType.MULTI_PART)]) -> dict:
        recognizer_service: RecognizerService = inject.instance(RecognizerService)
        body = await data.read()
        return await recognizer_service.predict_dog_image(body)

    @post("/cats")
    async def beerds_cats(self, data: Annotated[UploadFile, Body(media_type=RequestEncodingType.MULTI_PART)]) -> dict:
        recognizer_service: RecognizerService = inject.instance(RecognizerService)
        body = await data.read()
        return await recognizer_service.predict_cat_image(body)
