namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Mummy is an ability that changes the attacker's ability to Mummy if it makes contact.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Mummy_(Ability)">Bulbapedia - Mummy</see>
/// </summary>
[Script(ScriptCategory.Ability, "mummy")]
public class Mummy : Script, IScriptOnIncomingHit
{
    /// <inheritdoc />
    public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit)
    {
        if (!move.GetHitData(target, hit).IsContact || move.User.ActiveAbility?.Name == "mummy" ||
            !move.Battle.Library.StaticLibrary.Abilities.TryGet("mummy", out var mummyAbility))
            return;

        move.Battle.EventHook.Invoke(new AbilityTriggerEvent(target));
        move.User.ChangeAbility(mummyAbility);
    }
}