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

PACKET_PATH = 'migration.hotfix.S_39_5_4.wi11533_port_universal_interface_VoE.PortCustomizingUniversalInterface'


class FixHumanResourcesImportListbox(ChangeDTPPacket):
    """Set the correct listbox module in "Schnellerfassung Mitarbeiter" """
    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 13013

    def get_dependencies(self):
        return (PacketDependency(packet_path=PACKET_PATH, expected_state=PacketState.INSTALLED),
                MaxVersionDependency(version='39.5.2', version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        record = self.get_record(dt_num=411, key_list=['054111', 747287], di_list=['lb_module'])

        if not self.change_value(record=record, attribute='lb_module', old_value='009C2V', new_value='009CC5'):
            return self.fail('Could not change the listbox module')

        return self.success()