# -*- coding: utf-8 -*-
from ppms.migration.packet import *


class UpdateMappingClassExistsValuerange(MigratePythonPacket):
    '''Update a interface DI to allow for easier integration of customer functions'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 12027

    def fix(self, runner):
        BEFORE_HASH = '7247f14e5ca62b742b809ff56a3399c0'
        AFTER_HASH = '6ad59450fb0d3cb3b94e6a0557318cb1'

        fixfunc = lambda _: """from ppms.interface import UndefinedMapping, MAPPING_FUNCTIONS, get_mapping_instance_from_uuid

def computeOutput(di):
    record = di.get_dtp_record()

    _type = record.type.get_value()

    # Source/Pool/Target Mappings are always welcome
    if _type not in MAPPING_FUNCTIONS:
        return True

    uuid = record.uuid.get_value()
    instance = get_mapping_instance_from_uuid(uuid)

    return not isinstance(instance, UndefinedMapping)

computeOutput.deps = ('DI062652', 'DI062654')"""

        if self.migrate_python(BEFORE_HASH, AFTER_HASH,
                               self.CU_TYPE_DATAITEM, '062817',
                               fixfunc):
            return self.success()

        return self.fail()