import itertools

from .filter import Filter


class CropFilter(Filter):

    IDENTIFIER = 'crop'

    OUTPUT_WIDTH_KEY = 'output_width'
    OUTPUT_HEIGHT_KEY = 'output_height'
    OFFSET_X_KEY = 'x_offset'
    OFFSET_Y_KEY = 'y_offset'

    def __init__(self, **kwargs):
        
        self.__outputWidth = int(kwargs.get(CropFilter.OUTPUT_WIDTH_KEY, 0))
        self.__outputHeight = int(kwargs.get(CropFilter.OUTPUT_HEIGHT_KEY, 0))
        self.__offsetX = int(kwargs.get(CropFilter.OFFSET_X_KEY, 0))
        self.__offsetY = int(kwargs.get(CropFilter.OFFSET_Y_KEY, 0))

        super().__init__(self)

    def setArguments(self, **kwargs):
        self.__outputWidth = int(kwargs.get(CropFilter.OUTPUT_WIDTH_KEY))
        self.__outputHeight = int(kwargs.get(CropFilter.OUTPUT_HEIGHT_KEY))
        self.__offsetX = int(kwargs.get(CropFilter.OFFSET_X_KEY,))
        self.__offsetY = int(kwargs.get(CropFilter.OFFSET_Y_KEY,))

    def getPayload(self):

        payload = {'identifier': CropFilter.IDENTIFIER,
                   'parameters': {
                        CropFilter.OUTPUT_WIDTH_KEY: self.__outputWidth,
                        CropFilter.OUTPUT_HEIGHT_KEY: self.__outputHeight,
                        CropFilter.OFFSET_X_KEY: self.__offsetX,
                        CropFilter.OFFSET_Y_KEY: self.__offsetY
                    },
                    'suffices': [],
                    'variant': f"C{self.__outputWidth}-{self.__outputHeight}-{self.__offsetX}-{self.__offsetY}",
                    'tokens': ['crop='
                                + f"{self.__outputWidth}"
                                + f":{self.__outputHeight}"
                                + f":{self.__offsetX}"
                                + f":{self.__offsetY}"]}

        return payload


    def getYield(self):          
        yield self.getPayload()
