# -*- coding: utf-8 -*-
from ppms.migration import SQLPacket, PacketCategory
from ppms.resources import get_maximum_working_hours_per_day


class SetMaxHoursPerDay(SQLPacket):
    """Set max hours per day column for all resources with type 1*.

    The value is defined in the global setting 'maximum_work_hours_per_day'.
    """
    run_on_startup = False
    done_after_success = True
    category = PacketCategory.CATEGORY_HELPER
    wi_number = 22158

    def fix(self, packet_runner):
        max_hours_per_day = get_maximum_working_hours_per_day()
        update_stmt = """update DT467 set DI023345={max_hours_per_day} where DI003414 like '1%'""".format(
            max_hours_per_day=max_hours_per_day)
        self.modify_and_log(update_stmt)
        return self.success()
