from .ImageManipulation import ImageManipulation
from ImageContainer import ImageContainer
from typing import Any, List
from utils.image_utils import pil_to_cv2, cv2_to_pil
import cv2


class Padding(ImageManipulation):
    def getManipulationName(self) -> str:
        return "Padding"

    def getParameters(self) -> List[str]:
        return ["border_width"]

    def manipulateImage(self, image: ImageContainer, parameters: Any) -> None:
        if image is None or image.getImage() is None:
            return
        pil_img = image.getImage()
        cv_img = pil_to_cv2(pil_img)
        border_width = 50
        if isinstance(parameters, dict) and parameters.get("border_width") is not None:
            border_width = int(parameters.get("border_width"))
        padded = cv2.copyMakeBorder(
            cv_img,
            top=border_width,
            bottom=border_width,
            left=border_width,
            right=border_width,
            borderType=cv2.BORDER_REFLECT,
        )
        image._imageData = cv2_to_pil(padded)


