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

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

class CopyHyperlink(SQLPacket):
    """Sets DI040837 hdi_ajust_source to NULL where it is set for a hyperlink DI

    Hyperlink DIs in status report context have to be entered into the mapping found in create_report.py
    """

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

    __PATH = r'migration.server.S_39_5_13.wi12349_add_entity.Entity'
    UPDATE = """UPDATE DT412 SET DI040837 = '' WHERE DI041246 IN (16, 281, 282) AND DI040837 IS NOT NULL"""

    def get_dependencies(self):
        return (MinVersionDependency(version='39.4', version_type=VersionType.CUSTOMIZING),
                MaxVersionDependency(version='39.5.5', version_type=VersionType.CUSTOMIZING),
                PacketDependency(packet_path=self.__PATH, expected_state=PacketState.INSTALLED))

    def fix(self, runner):
        self.modify_and_log(self.UPDATE)
        return self.success()
