namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "switcheroo")]
public class Switcheroo : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var targetHeldItem = target.HeldItem;
        var userHeldItem = move.User.HeldItem;
        if (targetHeldItem?.Category is ItemCategory.FormChanger or ItemCategory.Mail ||
            userHeldItem?.Category is ItemCategory.FormChanger or ItemCategory.Mail)
        {
            // Cannot switch items if one of them is a form changer or mail
            move.GetHitData(target, hit).Fail();
            return;
        }
        targetHeldItem = target.RemoveHeldItem();
        userHeldItem = move.User.RemoveHeldItem();

        _ = target.ForceSetHeldItem(userHeldItem);
        _ = move.User.ForceSetHeldItem(targetHeldItem);
    }
}