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

class StandardIndexCorrection(SQLPacket):
    '''Fix a error in the portfolio management due to wrong indexes''' 
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10571

    update_characteristics = """UPDATE DT412 SET DI002461 = 1 WHERE DI000238 IN (9097, 27283, 27284, 29739, 29740, 29741)"""
    update_index_80 = """UPDATE DT412 SET DI000242 = 80 WHERE DI000238 IN (40272, 40277)"""
    update_index_82 = """UPDATE DT412 SET DI000242 = 82 WHERE DI000238 IN (40646, 40648)"""
    update_index_552 = """UPDATE DT412 SET DI000242 = 552 WHERE DI000238 = 3607"""

    def fix(self, runner):
        self.modify_and_log(self.update_characteristics)
        self.modify_and_log(self.update_index_80)
        self.modify_and_log(self.update_index_82)
        self.modify_and_log(self.update_index_552)

        return self.success()
