# -*- coding: utf-8 -*-
from ppms.migration import SQLPacket, PacketCategory, MaxVersionDependency, VersionType


class RemoveUnnecessaryAutoNr(SQLPacket):
    '''Remove auto-nr from some DIs where it doesn't make sense.

    DT465.DI001200
    DT465.DI001201
    DT465.DI001203
    '''
    wi_number = 14197
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY

    SQL = """{} FROM DT439
               WHERE DI000361 in ('001200', '001201', '001203')"""

    def get_dependencies(self):
        return (MaxVersionDependency(version='39.5.7', version_type=VersionType.CUSTOMIZING), )
    
    def fix(self, runner):
        if self.select_and_log(self.SQL.format("SELECT 1")):
            if not self.modify_and_log(self.SQL.format("DELETE")):
                return self.fail()

        return self.success()