# -*- coding: utf-8 -*-
from ppms.migration import SQLPacket, PacketCategory, MaxVersionDependency, VersionType
from ppms import ppms


class ChangeUnusedDI026621(SQLPacket):
    """Changing unsed DI026621 and adding new I-Text Names for it"""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 20915
    sql_script = """update dt412 set DI000246 = '8', 
                                     DI041035 = 'child_di_symbol2'
                    where di000238 = '026621'"""

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

    def fix(self, packet_runner):

        self.modify_and_log("update dt440 set DI026621 = null where di026621 is not null")
        self.modify_and_log(self.sql_script)

        dict = {'DE': 'Sekundäre Symbol ID',
                'FR': 'ID Symbole secondaire',
                'EN': 'Secondary Symbol ID'}
        i_text = '298845'

        for language, new_name in dict.items():
            self.modify_and_log("update dt435 set DI001549 = '{new_name}' where di001538 = '{i_text}' and "
                                "di001550 = '{language}'".format(new_name=new_name, i_text=i_text, language=language))

        return self.success()
