# -*- coding: utf-8 -*-
from ppms import ppms
from ppms.constants import *

from ppms.migration import SQLPacket, PacketCategory, VersionType, \
    MinVersionDependency, MaxVersionDependency


class CreateFederalStateColumn(SQLPacket):
    """Create the FEDERAL_STATE column in DT 430"""
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14754

    query_path = 'wi14754_calendar.sql'

    def get_dependencies(self):
        return (MinVersionDependency(version='39.5.6',
                                     version_type=VersionType.CUSTOMIZING),
                MaxVersionDependency(version='39.5.6',
                                     version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        self.apply_dml_file(self.sql_planta_de_dbms, self.query_path, split=False)

        return self.success()
    
    
class ExtendDescriptionColumn(SQLPacket):
    """Extend the description column in DT 560"""
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14754

    ALTER_TABLE_STATEMENTS = {DBMS_ORACLE: "ALTER TABLE INTERFACE_CONFIG MODIFY DESCRIPTION VARCHAR2(400)",
                              DBMS_MSSQL: "ALTER TABLE INTERFACE_CONFIG ALTER COLUMN DESCRIPTION VARCHAR(400)"}

    def get_dependencies(self):
        return (MinVersionDependency(version='39.5.6',
                                     version_type=VersionType.CUSTOMIZING),
                MaxVersionDependency(version='39.5.7',
                                     version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        self.modify_and_log(self.ALTER_TABLE_STATEMENTS[ppms.db_get_dbms_name()])

        return self.success()
