namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Regenerator is an ability that restores a little HP when the Pokémon switches out.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Regenerator_(Ability)">Bulbapedia - Regenerator</see>
/// </summary>
[Script(ScriptCategory.Ability, "regenerator")]
public class Regenerator : Script, IScriptOnSwitchOut
{
    /// <inheritdoc />
    public void OnSwitchOut(IPokemon oldPokemon, byte position)
    {
        if (!oldPokemon.IsUsable)
            return;

        EventBatchId batchId = new();
        oldPokemon.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(oldPokemon)
        {
            BatchId = batchId,
        });
        oldPokemon.Heal(oldPokemon.MaxHealth / 3, batchId: batchId);
    }
}