namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Rattled is an ability that raises Speed when hit by a Bug-, Ghost-, or Dark-type move.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Rattled_(Ability)">Bulbapedia - Rattled</see>
/// </summary>
[Script(ScriptCategory.Ability, "rattled")]
public class Rattled : Script, IScriptOnIncomingHit
{
    /// <inheritdoc />
    public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit)
    {
        var type = move.GetHitData(target, hit).Type;
        if (type is null)
            return;
        if (type.Value.Name != "bug" && type.Value.Name != "ghost" && type.Value.Name != "dark")
            return;
        target.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(target));
        target.ChangeStatBoost(Statistic.Speed, 1, true, false);
    }
}