import itertools

from .filter import Filter


class DeinterlaceFilter(Filter):

    IDENTIFIER = 'bwdif'

    # DEFAULT_STRENGTH: float = 2.8
    # DEFAULT_PATCH_SIZE: int = 13
    # DEFAULT_CHROMA_PATCH_SIZE: int = 9
    # DEFAULT_RESEARCH_WINDOW: int = 23
    # DEFAULT_CHROMA_RESEARCH_WINDOW: int= 17

    # STRENGTH_KEY = 'strength'
    # PATCH_SIZE_KEY = 'patch_size'
    # CHROMA_PATCH_SIZE_KEY = 'chroma_patch_size'
    # RESEARCH_WINDOW_KEY = 'research_window'
    # CHROMA_RESEARCH_WINDOW_KEY = 'chroma_research_window'


    def __init__(self, **kwargs):
        
        # self.__useHardware = kwargs.get('use_hardware', False)

        # self.__strengthList = []
        # strength = kwargs.get(NlmeansFilter.STRENGTH_KEY, '')
        # if strength:
        #     strengthTokens = strength.split(',')
        #     for st in strengthTokens:
        #         try:
        #             strengthValue = float(st)
        #         except:
        #             raise ValueError('NlmeansFilter: Strength value has to be of type float')
        #         if strengthValue < 1.0 or strengthValue > 30.0:
        #             raise ValueError('NlmeansFilter: Strength value has to be between 1.0 and 30.0')
        #         self.__strengthList.append(strengthValue)
        # else:
        #     self.__strengthList = [NlmeansFilter.DEFAULT_STRENGTH]

        # self.__patchSizeList = []
        # patchSize = kwargs.get(NlmeansFilter.PATCH_SIZE_KEY, '')
        # if patchSize:
        #     patchSizeTokens = patchSize.split(',')
        #     for pst in patchSizeTokens:
        #         try:
        #             patchSizeValue = int(pst)
        #         except:
        #             raise ValueError('NlmeansFilter: Patch size value has to be of type int')
        #         if patchSizeValue < 0 or patchSizeValue > 99:
        #             raise ValueError('NlmeansFilter: Patch size value has to be between 0 and 99')
        #         if patchSizeValue % 2 == 0:
        #             raise ValueError('NlmeansFilter: Patch size value has to an odd number')
        #         self.__patchSizeList.append(patchSizeValue)
        # else:
        #     self.__patchSizeList = [NlmeansFilter.DEFAULT_PATCH_SIZE]

        # self.__chromaPatchSizeList = []
        # chromaPatchSize = kwargs.get(NlmeansFilter.CHROMA_PATCH_SIZE_KEY, '')
        # if chromaPatchSize:
        #     chromaPatchSizeTokens = chromaPatchSize.split(',')
        #     for cpst in chromaPatchSizeTokens:
        #         try:
        #             chromaPatchSizeValue = int(pst)
        #         except:
        #             raise ValueError('NlmeansFilter: Chroma patch size value has to be of type int')
        #         if chromaPatchSizeValue < 0 or chromaPatchSizeValue > 99:
        #             raise ValueError('NlmeansFilter: Chroma patch value has to be between 0 and 99')
        #         if chromaPatchSizeValue % 2 == 0:
        #             raise ValueError('NlmeansFilter: Chroma patch value has to an odd number')
        #         self.__chromaPatchSizeList.append(chromaPatchSizeValue)
        # else:
        #     self.__chromaPatchSizeList = [NlmeansFilter.DEFAULT_CHROMA_PATCH_SIZE]

        # self.__researchWindowList = []
        # researchWindow = kwargs.get(NlmeansFilter.RESEARCH_WINDOW_KEY, '')
        # if researchWindow:
        #     researchWindowTokens = researchWindow.split(',')
        #     for rwt in researchWindowTokens:
        #         try:
        #             researchWindowValue = int(rwt)
        #         except:
        #             raise ValueError('NlmeansFilter: Research window value has to be of type int')
        #         if researchWindowValue < 0 or researchWindowValue > 99:
        #             raise ValueError('NlmeansFilter: Research window value has to be between 0 and 99')
        #         if researchWindowValue % 2 == 0:
        #             raise ValueError('NlmeansFilter: Research window value has to an odd number')
        #         self.__researchWindowList.append(researchWindowValue)
        # else:
        #     self.__researchWindowList = [NlmeansFilter.DEFAULT_RESEARCH_WINDOW]

        # self.__chromaResearchWindowList = []
        # chromaResearchWindow = kwargs.get(NlmeansFilter.CHROMA_RESEARCH_WINDOW_KEY, '')
        # if chromaResearchWindow:
        #     chromaResearchWindowTokens = chromaResearchWindow.split(',')
        #     for crwt in chromaResearchWindowTokens:
        #         try:
        #             chromaResearchWindowValue = int(crwt)
        #         except:
        #             raise ValueError('NlmeansFilter: Chroma research window value has to be of type int')
        #         if chromaResearchWindowValue < 0 or chromaResearchWindowValue > 99:
        #             raise ValueError('NlmeansFilter: Chroma research window value has to be between 0 and 99')
        #         if chromaResearchWindowValue % 2 == 0:
        #             raise ValueError('NlmeansFilter: Chroma research window value has to an odd number')
        #         self.__chromaResearchWindowList.append(chromaResearchWindowValue)
        # else:
        #     self.__chromaResearchWindowList = [NlmeansFilter.DEFAULT_CHROMA_RESEARCH_WINDOW]

        super().__init__(self)


    def getPayload(self):

        # strength = iteration[0]
        # patchSize = iteration[1]
        # chromaPatchSize = iteration[2]
        # researchWindow = iteration[3]
        # chromaResearchWindow = iteration[4]

        suffices = []

        # filterName = 'nlmeans_opencl' if self.__useHardware else 'nlmeans'

        payload = {'identifier': DeinterlaceFilter.IDENTIFIER,
                   'parameters': {},
                    'suffices': suffices,
                    'variant': f"DEINT",
                    'tokens': ['bwdif=mode=1']}
        
        return payload


    def getYield(self):
        # for it in itertools.product(self.__strengthList,
        #                                     self.__patchSizeList,
        #                                     self.__chromaPatchSizeList,
        #                                     self.__researchWindowList,
        #                                     self.__chromaResearchWindowList):            
        yield self.getPayload()
