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

BEFORE_HASH = 'c8f99ba26f95e8d8fcf6a2ff6b75f85f'
AFTER_HASH = '0ece6c5c048d4166db84f869cf1d48ce'

SUB = lambda _: """def processInput(di, oldvalue):
    newVal = di.get_value()
    df_length = di.get_dtp_record().df_length.get_value()

    if len(newVal) <= df_length:
        return newVal
    else:
        ppms.ui_message_id('0520')
        return oldvalue

processInput.deps=('DI000361', 'DI006108')"""

class ChangeAutoNumberValueRange(MigratePythonPacket):
    '''Fix a Python error with the automatic number value range'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 8281

    def fix(self, runner):
        if not self.migrate_python(BEFORE_HASH, AFTER_HASH,
                                   self.CU_TYPE_DATAITEM, '000002', SUB):
            return self.fail()

        return self.success()
