# -*- coding: utf-8 -*-
import os

from ppms.migration.packet import *

BEFORE_HASH = '2f88ea70d9df2619c9629cda2252cb6d'
AFTER_HASH = 'e913a430cb7f0371105444a54f6a30f9'

class AddModuleClassTwelvePacket(MigratePythonPacket):
    '''Port the new module class 12 for dialog modules to Venus on Earth'''
    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10568

    def fix(self, runner):
        fix_func = lambda code: code.replace('11,16', '11,12,16')

        if self.migrate_python(BEFORE_HASH, AFTER_HASH,
                               self.CU_TYPE_DATAITEM, '000127', fix_func):
            return self.success()

        return self.fail()

class PortDialogModuleCUPacket(SQLPacket):
    '''Port the new customizing parameters for dialog modules to Venus on Earth'''
    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10568

    fname = 'wi10568_port_dialog_module_cu.sql'

    def fix(self, runner):
        sqlpath = self.get_sql_file_path(self.sql_planta_de_dbms, self.fname)
        queries = self.get_queries_from_file(sqlpath)

        for query in queries:
            self.modify_and_log(query)

        return self.success()

