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

class AddParentResourceDiToScheduling(SQLPacket):
    '''Scheduling needs to adopt the new way of resource structuring.

    Originally, N-dimensional resource structure was implemented via
    DT 469, albeit the various dimensions were not so clearly separated.
    These days anyway, there is a DI 009753 "superior resource" in DT467
    which is supposed to handle the new 1-dimensional pattern.

    Scheduling code however still crawls DT 469 exclusively, and DI 009753
    is not even flagged for use by scheduling. Ensure we can at least
    work with the current information, the rest is to be done in the code.
    '''
    version = 1
    done_after_success = True
    run_on_startup = True
    wi_number = 11120
    category = PacketCategory.CATEGORY_MANDATORY

    def fix(self, runner):
        query_scheduling_read = """UPDATE DT412 SET DI028175 = 1 WHERE DI000238 = '009753'"""

        self.log('Enabling "read" bit in "scheduling" bitfield for DI 009... "superordinate resource" in DT 467.')
        self.modify_and_log(query_scheduling_read)
        return self.success()
