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


class DeleteInconsistentStandardData(SQLPacket):
    """Deletes corrupt standard data so that the database integrity can be assured."""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 17578

    DELETE_STATEMENTS = ["""DELETE FROM DT439 where DI000361 = '003178'""",
                         """DELETE FROM DT346 where DI025404 in ('000070', '000071', '000072', '000073', '000074', '000075', '000069')""",
                         """DELETE FROM DT515 where DI010325 = '01100330' and DI010327 in ('003305', '002733')""",
                         """DELETE FROM DT519 where DI010685 = '01100025' and DI010686 = '01100029'""",
                         """DELETE FROM DT411 where DI000306 = '049759'""",
                         """DELETE FROM DT406 where DI000970 in ('009BE9', '0099Q1', '009A3E', '0099TX')""",
                         """DELETE FROM DT410 where DI000198 in ('050028', '049759')"""]

    def get_dependencies(self):
        return (MinVersionDependency(version='39.5.6'),
                MaxVersionDependency(version='39.5.6'))

    def fix(self, packet_runner):
        for statement in self.DELETE_STATEMENTS:
            self.modify_and_log(statement)
        return self.success()