# 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 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
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)


from .fixer import WowToolsFixer
from .tools import icat, changelog
            **({'itemId': int(item_id)} if item_id else {})
        }

    def get_pet_source(self, pet_id):
        return PET_SOURCE_ENUM.get(
            int(self.wt_battlepetspecies[pet_id]['SourceTypeEnum']),
            'Unknown'
        )

    def fix_missing_pet(self, pet_id):
        if (
            # Flag 0x20 : HideFromJournal
            int(self.wt_battlepetspecies[pet_id]['Flags']) & 0x20
            or (
                int(self.wt_battlepetspecies[pet_id]['CreatureID'])
                in IGNORE_PET_NPCID
            )
        ):
            return
        pet = self.get_pet(pet_id)
        if pet is None:
            return

        changelog('Pet {} missing: https://www.wowhead.com/npc={}'
                  .format(pet_id, pet['creatureId']))

        source = self.get_pet_source(pet_id)
        if source == 'Wild':
            icat(self.battlepets, 'TODO', 'TODO')['items'].append(pet)
        else:

# 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 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
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)


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

            **({'itemId': int(item_id)} if item_id else {})
        }

    def get_pet_source(self, pet_id):
        return PET_SOURCE_ENUM.get(
            int(self.wt_battlepetspecies[pet_id]['SourceTypeEnum']),
            'Unknown'
        )

    def fix_missing_pet(self, pet_id):
        if (
            # Flag 0x20 : HideFromJournal
            int(self.wt_battlepetspecies[pet_id]['Flags']) & 0x20
            or (
                int(self.wt_battlepetspecies[pet_id]['CreatureID'])
                in IGNORE_PET_NPCID
            )
        ):
            return
        pet = self.get_pet(pet_id)
        if pet is None:
            return

        changelog('Pet {} missing: https://www.wowhead.com/npc={}'
                  .format(pet_id, pet['creatureId']))

        source = self.get_pet_source(pet_id)
        if source == 'Wild':
            icat(self.battlepets, 'TODO', 'TODO')['items'].append(pet)
        else:

            icat(self.pets, 'TODO', source)['items'].append(pet)