from copy import deepcopy


# TODO: add types
# TODO: add unit tests
def loadContextFromConfig(config, context):
    context['ng_backpacks'] = config['ng_backpacks'].copy()
    context['general_hotkeys'] = config['general_hotkeys'].copy()
    context['auto_hur'] = config['auto_hur'].copy()
    context['alert'] = config['alert'].copy()
    context['clear_stats'] = config['clear_stats'].copy()
    context['ignorable_creatures'] = config['ignorable_creatures'].copy()
    context['ng_cave']['enabled'] = config['ng_cave']['enabled']
    context['ng_cave']['runToCreatures'] = config['ng_cave']['runToCreatures']
    context['ng_cave']['waypoints']['currentIndex'] = None
    context['ng_cave']['waypoints']['state'] = None
    context['ng_cave']['waypoints']['items'] = deepcopy(config['ng_cave']['waypoints']['items'])
    context['ng_comboSpells']['enabled'] = config['ng_comboSpells']['enabled']
    context['ng_comboSpells']['items'] = []
    for comboSpellsItem in config['ng_comboSpells']['items']:
        comboSpellsItem = deepcopy(comboSpellsItem)
        comboSpellsItem['currentSpellIndex'] = 0
        context['ng_comboSpells']['items'].append(comboSpellsItem)
    context['healing'] = deepcopy(config['healing'])
    context['ng_bbot'] = deepcopy(config.get('ng_bbot', {}))
    context['ng_actionBar'] = deepcopy(config.get('ng_actionBar', {}))
    context['ng_supplies'] = deepcopy(
        config.get('ng_supplies', {'enabled': False, 'rules': []}))
    context['ng_session'] = deepcopy(
        config.get('ng_session', {
            'enabled': False, 'huntMinutes': 240, 'offlineMinutes': 30,
        }))
    context['ng_lootRules'] = deepcopy(config.get('ng_lootRules', []))
    context['ng_lootDropUnwanted'] = bool(
        config.get('ng_lootDropUnwanted', False))
    context['ng_deathConfig'] = deepcopy(config.get('ng_deathConfig', {}))
    targeting = config.get('ng_targeting', {})
    context['ng_targeting']['creatures'] = deepcopy(targeting.get('creatures', {}))
    context['ng_targeting']['enabled'] = bool(context['ng_targeting']['creatures'])
    return context

def loadNgCfgs(config, context):
    context['ng_backpacks'] = config['ng_backpacks'].copy()
    context['general_hotkeys'] = config['general_hotkeys'].copy()
    context['auto_hur'] = config['auto_hur'].copy()
    context['alert'] = config['alert'].copy()
    context['clear_stats'] = config['clear_stats'].copy()
    context['ng_comboSpells']['enabled'] = config['ng_comboSpells']['enabled']
    context['ng_comboSpells']['items'] = []
    for comboSpellsItem in config['ng_comboSpells']['items']:
        comboSpellsItem = deepcopy(comboSpellsItem)
        comboSpellsItem['currentSpellIndex'] = 0
        context['ng_comboSpells']['items'].append(comboSpellsItem)
    context['healing'] = deepcopy(config['healing'])
    context['ng_actionBar'] = deepcopy(config.get('ng_actionBar', {}))
    context['ng_supplies'] = deepcopy(
        config.get('ng_supplies', {'enabled': False, 'rules': []}))
    context['ng_session'] = deepcopy(
        config.get('ng_session', {
            'enabled': False, 'huntMinutes': 240, 'offlineMinutes': 30,
        }))
    context['ng_lootRules'] = deepcopy(config.get('ng_lootRules', []))
    context['ng_lootDropUnwanted'] = bool(
        config.get('ng_lootDropUnwanted', False))
    return context
