namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "bestow")]
public class Bestow : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var user = move.User;
        var userHeldItem = user.HeldItem;
        var targetHeldItem = target.HeldItem;

        if (userHeldItem == null || targetHeldItem != null)
        {
            move.GetHitData(target, hit).Fail();
            return;
        }
        userHeldItem = user.RemoveHeldItemForBattle();
        _ = target.ForceSetHeldItem(userHeldItem);
    }
}