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

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


class FixHumanResourcesPoolCustomizing(ChangeDTPPacket):
    """Correct 2 customizing mistakes in MOD 009C6Y"""
    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 13041

    def get_dependencies(self):
        return PacketDependency(packet_path=PACKET_PATH, expected_state=PacketState.INSTALLED)

    def fix(self, runner):
        record = self.get_record(dt_num=411, key_list=['054064', 745032], di_list=['behavior', 'filter_to'])

        failures = 0

        for attribute, old_value, new_value in (('behavior', 'o2', 'i'), ('filter_to', '', '1')):
            if not self.change_value(record=record, attribute=attribute, old_value=old_value, new_value=new_value):
                failures += 1

        if failures:
            return self.fail('Could not update DI 062842')

        return self.success()