# -*- coding: utf-8 -*-
from ppms import ppms
from ppms.constants import *
from ppms.migration import SQLPacket, PacketCategory, MaxVersionDependency, MinVersionDependency, VersionType, PacketDependency, \
    PacketState, BasePacket
STATEMENTS = ["UPDATE DT447 SET DI041270 = '011' WHERE DI041270 IS NULL OR DI041270 = ('')",
              "UPDATE DT447 SET DI041269 = 'P20' WHERE DI041269 LIKE '%8'",
              "UPDATE DT447 SET DI041268 = 'P20' WHERE DI041268 LIKE '%8'"]
               
class FixNullValuesInDT447(SQLPacket):

    "Fixing Null Values for OWNER_LICENSE in DT447 although correcting created_from / changed_from"

    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 17557

    def get_dependencies(self):
        return MaxVersionDependency(version='39.4' ,version_type=VersionType.CUSTOMIZING)

    def fix(self, runner):
        for statement in STATEMENTS:
            self.modify_and_log(statement)
        
        return self.success()