# Path: OpenNumismat/Collection/CollectionFields.py
# class FieldTypes():
#     String = 1
#     ShortString = 2
#     Number = 3
#     Text = 4
#     Money = 5
#     Date = 6
#     BigInt = 7
#     Image = 8
#     Value = 9
#     Status = 10
#     DateTime = 11
#     PreviewImage = 13
#     Denomination = 14
# 
#     Mask = 0xFF
#     Checkable = 0x100
#     Disabled = 0x200
# 
#     ImageTypes = (Image, PreviewImage)
# 
#     @staticmethod
#     def toSql(type_):
#         if type_ == FieldTypes.String:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.ShortString:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Number:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Text:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Money:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Denomination:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Date:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.BigInt:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.PreviewImage:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Image:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Value:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Status:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.DateTime:
#             sql_type = 'TEXT'
#         else:
#             raise TypeError
# 
#         return sql_type
# 
# Path: OpenNumismat/Tools/Gui.py
# class ProgressDialog(QProgressDialog):
#     def __init__(self, labelText, cancelButtonText, maximum, parent=None):
#     def step(self):
#     def setLabelText(self, text):
# def statusIcon(status):
# def getSaveFileName(parent, name, filename, dir_, filters):


from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from PyQt5.QtSql import QSqlQuery
from PyQt5.QtCore import QSettings
from OpenNumismat.Collection.CollectionFields import FieldTypes as Type
from OpenNumismat.Tools import Gui



class UpdaterTo6(_Updater):

    def __init__(self, collection):
        super().__init__(collection)
        self.progressDlg.setMinimumDuration(0)

    def getTotalCount(self):
        return 3

    def update(self):
        self._begin()

        self.db.transaction()

        fields = ('category', 'sort_id')
        for field in fields:
            self._updateRecord()

            fieldDesc = getattr(self.collection.fields, field)
            fieldDesc.enabled = False
            query = QSqlQuery(self.db)
            query.prepare("INSERT INTO fields (id, title, enabled)"
                          " VALUES (?, ?, ?)")
            query.addBindValue(fieldDesc.id)
            query.addBindValue(fieldDesc.title)
            query.addBindValue(int(False))
            query.exec_()


# Path: OpenNumismat/Collection/CollectionFields.py
# class FieldTypes():
#     String = 1
#     ShortString = 2
#     Number = 3
#     Text = 4
#     Money = 5
#     Date = 6
#     BigInt = 7
#     Image = 8
#     Value = 9
#     Status = 10
#     DateTime = 11
#     PreviewImage = 13
#     Denomination = 14
# 
#     Mask = 0xFF
#     Checkable = 0x100
#     Disabled = 0x200
# 
#     ImageTypes = (Image, PreviewImage)
# 
#     @staticmethod
#     def toSql(type_):
#         if type_ == FieldTypes.String:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.ShortString:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Number:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Text:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Money:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Denomination:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Date:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.BigInt:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.PreviewImage:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Image:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Value:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Status:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.DateTime:
#             sql_type = 'TEXT'
#         else:
#             raise TypeError
# 
#         return sql_type
# 
# Path: OpenNumismat/Tools/Gui.py
# class ProgressDialog(QProgressDialog):
#     def __init__(self, labelText, cancelButtonText, maximum, parent=None):
#     def step(self):
#     def setLabelText(self, text):
# def statusIcon(status):
# def getSaveFileName(parent, name, filename, dir_, filters):


# Path: OpenNumismat/Collection/VersionUpdater.py
from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from PyQt5.QtSql import QSqlQuery
from PyQt5.QtCore import QSettings
from OpenNumismat.Collection.CollectionFields import FieldTypes as Type
from OpenNumismat.Tools import Gui



class UpdaterTo6(_Updater):

    def __init__(self, collection):
        super().__init__(collection)
        self.progressDlg.setMinimumDuration(0)

    def getTotalCount(self):
        return 3

    def update(self):
        self._begin()

        self.db.transaction()

        fields = ('category', 'sort_id')
        for field in fields:
            self._updateRecord()

            fieldDesc = getattr(self.collection.fields, field)
            fieldDesc.enabled = False
            query = QSqlQuery(self.db)
            query.prepare("INSERT INTO fields (id, title, enabled)"
                          " VALUES (?, ?, ?)")
            query.addBindValue(fieldDesc.id)
            query.addBindValue(fieldDesc.title)
            query.addBindValue(int(False))
            query.exec_()


            sql = "ALTER TABLE coins ADD COLUMN %s %s" % (field, Type.toSql(fieldDesc.type))
