namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Water Absorb is an ability that heals the Pokémon when hit by a Water-type move.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Water_Absorb_(Ability)">Bulbapedia - Water Absorb</see>
/// </summary>
[Script(ScriptCategory.Ability, "water_absorb")]
public class WaterAbsorb : Script, IScriptIsInvulnerableToMove
{
    /// <inheritdoc />
    public void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable)
    {
        if (move.GetHitData(target, 0).Type?.Name != "water")
            return;
        invulnerable = true;
        target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target));
        target.Heal(target.MaxHealth / 4);
    }
}