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

class RemoveRestartServerButton(SQLPacket, ChangeDTPPacket):
    '''Remove "Restart Server" button from "Data Dictionary" module
 
    The functionality is still accessible via "Tools --> Reload System Customizing"
    '''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 11102
    
    def get_dependencies(self):
        return (MinVersionDependency(version='39.4', version_type=VersionType.CUSTOMIZING),
                MaxVersionDependency(version='39.5.5', version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        itexts = {731861: {'DE': (None, "System-Customizing neu laden"),
                           'EN': (None, "Reload System Customizing"),
                           'FR': (None, "Recharger customizing de système")},
                  731872: {'DE': (None, "Soll das System-Customizing neu geladen werden?"),
                           'EN': (None, "Do you want to reload the System Customizing?"),
                           'FR': (None, "Veuillez redémarrer le customizing de système?")},
                  731873: {'DE': (None, "Das System-Customizing wird neu geladen. Client-Verbindungen sind in ca. 10 bis 20 Sekunden wieder möglich."),
                           'EN': (None, "The System Customizing is being reloaded. Client connections will be available again in 10 to 20 seconds."),
                           'FR': (None, "Le customizing de système a été démarré avec succès")}}

        self.modify_and_log("DELETE FROM DT411 WHERE DI000306 = '031149' AND DI000307 = 146695")

        for id, values in itexts.items():
            for language, (old_value, new_value) in values.items():
                itext_rec = self.get_record(435, [id, language], ['i_text'])
                if not self.change_value(itext_rec, 'i_text', old_value, new_value):
                    return self.fail()

        return self.success()