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

class ChangeInvalidEntityName(SQLPacket):
    """Remove invalid character from EntityNames of DTs 912, 807, 092, 914, 573, 575, 576 and 485"""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14035

    SQL = ("""UPDATE DT415 SET ENTITYNAME = 'ContentSkillAssignment' WHERE DI000265 = '912' AND ENTITYNAME = 'Content-SkillAssignment'""",
           """UPDATE DT415 SET ENTITYNAME = 'MSPILink' WHERE DI000265 = '807' AND ENTITYNAME = 'MSPI-Link'""",
           """UPDATE DT415 SET ENTITYNAME = 'PFSRPerKTGr' WHERE DI000265 = '092' AND ENTITYNAME = 'PF-SRPerKTGr'""",
           """UPDATE DT415 SET ENTITYNAME = 'PersonSkillAssignment' WHERE DI000265 = '914' AND ENTITYNAME = 'Person-SkillAssignment'""",
           """UPDATE DT415 SET ENTITYNAME = 'ResourceSkillAssignment' WHERE DI000265 = '485' AND ENTITYNAME = 'Resource-SkillAssignment'""",
           """UPDATE DT415 SET ENTITYNAME = 'SAPActualCostsImport1' WHERE DI000265 = '573' AND ENTITYNAME = 'SAPActualCosts,Import1'""",
           """UPDATE DT415 SET ENTITYNAME = 'SAPActualCostsImport2' WHERE DI000265 = '575' AND ENTITYNAME = 'SAPActualCosts,Import2'""",
           """UPDATE DT415 SET ENTITYNAME = 'SAPActualCostsImport3' WHERE DI000265 = '576' AND ENTITYNAME = 'SAPActualCosts,Import3'""")
    

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