# -*- coding: latin-1 -*-
from ppms.migration import MaxVersionDependency, VersionType
from ppms.migration.packet import *


class ChangeStandardCUforDialogModulesinDataDictionary(ChangeDTPPacket):
    ''' Change standard value for dialog modules in data dictionary'''
    wi_number = 8630
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY

    def get_dependencies(self):
        return (MaxVersionDependency(version='39.5.2', version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        values = [['060068','sql_defaultvalue','5','']
                  ]

        for di_id, df_name, old_value, new_value in values:
            record = self.get_record(412, [di_id], [26799])
            if not self.change_value(record, df_name, old_value, new_value):
                return self.fail()

        return self.success()

class ChangeStandardCUforDialogModulesinDB(SQLPacket):
    ''' Change standard value for dialog modules in database'''
    wi_number = 8630
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY

    fname = 'wi8630_change_standard_cu_for_dialog_modules.sql'

    def get_dependencies(self):
        return (MaxVersionDependency(version='39.5.2', version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        self.apply_dml_file(self.sql_planta_de_dbms, self.fname)

        return self.success()