# -*- coding: utf-8 -*-
import os

from ppms.migration.packet import *

BEFORE_HASH = '07bf8ce8fe76dd608abda227638c1378'
AFTER_HASH = 'f806c851abae2afe94943453908acb79'
SUB = lambda _: """from ppms.client_editor import subclass_editor

subclass_editor.main()"""

class ChangeSubclassEditor(MigratePythonPacket, ChangeDTPPacket, SQLPacket):
    '''Migrate the subclass editor from Venus to Venus on Earth'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 11190

    fname = 'WI11190_subclass_editor.sql'

    def fix(self, runner):
        failures = 0

        sqlpath = self.get_sql_file_path(self.sql_planta_de_dbms, self.fname)
        queries = self.get_queries_from_file(sqlpath)

        for query in queries:
            if not self.modify_and_log(query):
                failures += 1

        record = self.get_record(428, ['0739'], [26385, 1765])
        if not self.change_value(record, 'ole_symbol', '', '000207'):
            failures += 1

        if not self.change_value(record, 'button_type', 1, 2):
            failures += 1

        if not self.migrate_python(BEFORE_HASH, AFTER_HASH,
                                   self.CU_TYPE_MODULE, '009B6H', SUB):
            failures += 1

        if failures:
            return self.fail()

        return self.success()
