using System.Collections.Generic;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Objects.Unit.Actions;
using VOID.Generic.Objects.Wearable;
using VOID.Generic.Player.Util;

namespace VOID.Generic.Player.DraggingOperation
{
    public class EquipmentToSceneDraggingOperation : AbstractDraggingOperation
    {
        public override bool Check(SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
        {
            return sourceSelect.slotUI?.slotType == SlotType.EquipmentSlot
                   && targetSelect.slotUI?.slotType == null;
        }

        public override void Perform(UnitObject unit, SelectUtilResult sourceSelect, SelectUtilResult targetSelect)
        {
            if (sourceSelect.selectObject is not WearableObject wearable) return;
            unit.OrderStop();
            unit.Order(new MoveAction(unit, targetSelect.position, unit.unitData.takeRange));
            unit.OrderChain(new List<AbstractAction>
            {
                new UnEquipAction(unit, wearable),
                new DropAction(unit, wearable, targetSelect.position)
            });
        }
    }
}