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


class ReactivateTables(SQLPacket):
    """Reactivate some tables that are still in use

    Unnecessary if:  * this is a Venus DB
                     * packet wi13741_disable_system_customizing hasn't run
    """

    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14079

    PACKET_PATH = 'migration.hotfix.S_39_5_13.z99_wi13741_disable_system_customizing.DisableObsoleteSystemCustomizing'

    SQL = """UPDATE DT415 SET ENABLED = 1 WHERE DI000265 IN ('150', '151', '152', '153', '495')"""


    def get_dependencies(self):
        return (MaxVersionDependency(version='39.4', version_type=VersionType.CUSTOMIZING),
                PacketDependency(packet_path=self.PACKET_PATH, expected_state=PacketState.INSTALLED))

    def fix(self, runner):
        if not self.modify_and_log(self.SQL):
            return self.fail()
        return self.success()