from src.gameplay.combo import _comboCastTask
from src.gameplay.core.tasks.castSpell import CastSpellTask
from src.gameplay.core.tasks.useComboHotkey import UseComboHotkeyTask
from src.gameplay.core.tasks.useHotkey import UseHotkeyTask
from src.gameplay.core.tasks.useSlotItem import UseSlotItemTask


def test_combo_cast_prefers_slot_click_in_smart_mode():
    context = {'ng_actionBar': {'smartHotkeys': True}}

    task = _comboCastTask(context, {'name': 'exori', 'slot': 2})

    assert isinstance(task, UseSlotItemTask)
    assert task.slot == 2


def test_combo_cast_falls_back_to_chat_in_smart_mode():
    context = {'ng_actionBar': {'smartHotkeys': True}}

    task = _comboCastTask(context, {'name': 'exori', 'slot': None})

    assert isinstance(task, CastSpellTask)
    assert task.spell == 'exori'


def test_combo_cast_is_none_without_smart_mode():
    context = {'ng_actionBar': {'smartHotkeys': False}}

    assert _comboCastTask(
        context, {'name': 'exori', 'slot': 2, 'hotkey': 'F9'}) is None


def test_combo_task_uses_custom_cast_task():
    task = UseComboHotkeyTask('F1', 'exori', useTask=CastSpellTask('exori'))
    task.onBeforeStart({})

    assert isinstance(task.tasks[0], CastSpellTask)


def test_combo_task_defaults_to_hotkey():
    task = UseComboHotkeyTask('F1', 'exori')
    task.onBeforeStart({})

    assert isinstance(task.tasks[0], UseHotkeyTask)


def test_combo_without_hotkey_casts_via_chat_even_without_smart_mode():
    context = {'ng_actionBar': {'smartHotkeys': False}}

    task = _comboCastTask(context, {'name': 'exevo gran mas vis', 'hotkey': None})

    assert isinstance(task, CastSpellTask)
    assert task.spell == 'exevo gran mas vis'
