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

# Oracle has some whitespace garbage, altering the hash
BEFORE_HASH = {DBMS_ORACLE: 'c4d7530b31b244a69ecc6c9b77bd5d28',
               DBMS_MSSQL: '24bcf54ebceec790a7351f8d87bb693d'}
AFTER_HASH = {DBMS_ORACLE: '15932f3d814b34369ba4d9cc5719fd97',
              DBMS_MSSQL: 'b5a06e6a696afbab33e0a5849c12ce67'}

SUB = lambda code: code.replace('int', 'float').replace('(input_actual_end[0])', '(input_actual_end[0].replace(\',\', \'.\'))')
DBMS = ppms.db_get_dbms_name()

class AllowFloatingHours(MigratePythonPacket):
    '''Allow floating-point numbers to be booked'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10221

    def fix(self, runner):
        if not self.migrate_python(BEFORE_HASH[DBMS], AFTER_HASH[DBMS],
                                   self.CU_TYPE_MODULE, '0099JK', SUB):
            return self.fail()
                                   
        return self.success()