using PkmnLib.Static.Moves;

namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Magician is an ability that steals the held item of a Pokémon it hits with a move.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Magician_(Ability)">Bulbapedia - Magician</see>
/// </summary>
[Script(ScriptCategory.Ability, "magician")]
public class Magician : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        if (move.UseMove.Category is MoveCategory.Status)
            return;

        if (move.User.HeldItem is not null || target.HeldItem is null)
            return;

        if (!move.User.TryStealHeldItem(out var item))
            return;

        move.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User));
        _ = move.User.ForceSetHeldItem(item);
    }
}