from ppms.migration import ChangeDTPPacket, PacketCategory, MinVersionDependency, MaxVersionDependency, VersionType


DATAFIELD_DICTIONARY = {
                    ('044181', 734079): {'window': [1, 9]},
                    ('044181', 734080): {'window': [1, 9]},
                    ('044181', 734087): {'window': [1, 9]}
                    }


class ChangeCustomizingForDialogModules(ChangeDTPPacket):
    """changes window-value for dialog-datafields in moduleparameters"""
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10955
    
    def get_dependencies(self):
        return (MinVersionDependency(version='39.5.0', version_type=VersionType.CUSTOMIZING),
                MaxVersionDependency(version='39.5.5', version_type=VersionType.CUSTOMIZING))
                
    def change_record(self, datatable, primary_key, change_dictionary):
        old_value = 0
        new_value = 1
        record = self.get_record(datatable, list(primary_key), list(change_dictionary.keys()))
        for field in change_dictionary.keys():
            old_new_values = change_dictionary.get(field)
            self.change_value(record, field, old_new_values[old_value], old_new_values[new_value])
            
    def fix(self, runner):
        for datafield in DATAFIELD_DICTIONARY.keys():
            self.change_record(411, datafield, DATAFIELD_DICTIONARY.get(datafield))
        return self.success()