# -*- coding: utf-8 -*-
from ppms.migration.packet import *
from . import DEFAULT_CUSTOMIZING_DEPENDENCY

CLEANUP_QUERIES = ["DELETE FROM DT435 WHERE DI023517 = '000296' AND DI001538 IN (SELECT DI000296 FROM DT425 WHERE "
                   "DI000295 = '001655') AND DI001544 = '011'",
                   "DELETE FROM DT425 WHERE DI000295 = '001655'"]


class PortCopyConfig(SQLPacket):
    '''Port the new cleanup routine for copying a configuration'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 12808

    fname = 'wi12808_copy_config.sql'

    def get_dependencies(self):
        return DEFAULT_CUSTOMIZING_DEPENDENCY

    def fix(self, runner):
        for query in CLEANUP_QUERIES:
            self.modify_and_log(query)

        self.apply_dml_file(self.sql_planta_de_dbms, self.fname)

        return self.success()
