# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name
# 
# Path: dataimporter/tools.py
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# def icat(dct, cat=None, subcat=None, error_absent=False):
#     if cat is not None:
#         res = find_or_create_item(dct, cat, 'subcats', error_absent)
#     if subcat is not None:
#         res = find_or_create_item(
#             res['subcats'], subcat, 'items', error_absent
#         )
#     return res


from .fixer import WowToolsFixer
from .tools import changelog, icat

    def get_toy(self, toy_id):
        toy_id = str(toy_id)

        # Name
        if toy_id not in self.wt_itemsparse:
            return None
        name = self.wt_itemsparse[toy_id]['Display_lang']

        # Icon
        icon_id = self.wt_item[toy_id]['IconFileDataID']
        icon_name = self.get_icon_name(int(icon_id))

        return {
            'itemId': int(toy_id),
            'name': name,
            'icon': icon_name,
        }

    def get_toy_source(self, toy_id):
        return TOY_SOURCE_ENUM.get(
            int(self.wt_toy[toy_id]['SourceTypeEnum']),
            'Unknown'
        )

    def fix_missing_toy(self, toy_id):
        toy = self.get_toy(toy_id)
        if toy is None:
            return


# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name
# 
# Path: dataimporter/tools.py
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# def icat(dct, cat=None, subcat=None, error_absent=False):
#     if cat is not None:
#         res = find_or_create_item(dct, cat, 'subcats', error_absent)
#     if subcat is not None:
#         res = find_or_create_item(
#             res['subcats'], subcat, 'items', error_absent
#         )
#     return res


# Path: dataimporter/toys.py
from .fixer import WowToolsFixer
from .tools import changelog, icat


    def get_toy(self, toy_id):
        toy_id = str(toy_id)

        # Name
        if toy_id not in self.wt_itemsparse:
            return None
        name = self.wt_itemsparse[toy_id]['Display_lang']

        # Icon
        icon_id = self.wt_item[toy_id]['IconFileDataID']
        icon_name = self.get_icon_name(int(icon_id))

        return {
            'itemId': int(toy_id),
            'name': name,
            'icon': icon_name,
        }

    def get_toy_source(self, toy_id):
        return TOY_SOURCE_ENUM.get(
            int(self.wt_toy[toy_id]['SourceTypeEnum']),
            'Unknown'
        )

    def fix_missing_toy(self, toy_id):
        toy = self.get_toy(toy_id)
        if toy is None:
            return


        changelog('Toy {} missing: https://www.wowhead.com/item={}'