# -*- coding: utf-8 -*-

from ppms.migration import SQLPacket, PacketCategory, MinVersionDependency, MaxVersionDependency, VersionType

class MissingTranslationsVoE(SQLPacket):
    """Add/fix some english translations in the migration context
    """

    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 13652

    UPDATE = ("""update dt435 set di001549 = 'The target module has successfully received the record.' where di001538 = 762797 and di001550 = 'EN' and di001549 = 'The target module has seccessfully received the record.'""",
              """update dt435 set di001549 = 'The transfer is not carried out because of critical error.' where di001538 = 763010 and di001550 = 'EN' and di001549 = 'The transfer is not carried out because of criticl error.'""",
              """update dt435 set di001549 = 'Mandatory packets' where di001538 = 799441 and di001550 = 'EN' and di001549 is null""",
              """update dt435 set di001549 = 'Special functions' where di001538 = 799446 and di001550 = 'EN' and di001549 is null""",
              """update dt435 set di001549 = 'Completed packets' where di001538 = 799454 and di001550 = 'EN' and di001549 is null""",
              """update dt435 set di001549 = 'Invalid packets' where di001538 = 799779 and di001550 = 'EN' and di001549 is null""")

    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):
        for statement in self.UPDATE:
            self.modify_and_log(statement)
        return self.success()
