# -*- coding: utf-8 -*-
import os
from ppms.migration.packet import *
from ppms.migration import VersionType, MinVersionDependency, MaxVersionDependency

class NewDialogMessages(SQLPacket, ChangeDTPPacket):
    '''Creates new Dialog Messages
    - 1) Der gewünschte Entity-Name wird bereits verwendet
    - 2) Python-ID darf nicht leer sein
    '''
    
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 13896

    fname = 'wi13896_add_new_dialog_messages.sql'
    
    def get_dependencies(self):
        return (MinVersionDependency(version='39.5', version_type=VersionType.CUSTOMIZING),
                MaxVersionDependency(version='39.5.5', version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        sqlpath = self.get_sql_file_path(self.sql_planta_de_dbms, self.fname)

        queries = self.get_queries_from_file(sqlpath)

        for query in queries:
            try:
                self.modify_and_log(query)
            except Exception as e:
                if 'ORA-00001' in str(e):
                    self.log("Skipped because Itext or dialog message already exists")
                else:
                    raise e

        return self.success()
