namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

/// <summary>
/// The user applies pressure to stress points, sharply boosting one of its or its allies' stats. 
/// </summary>
/// <remarks>
/// Acupressure chooses one of the target's stats at random and raises it by two stages. It can raise either the
/// target's Attack, Defense, Special Attack, Special Defense, Speed, accuracy or evasion stat but will not attempt
/// to raise a stat that is already maximized, meaning that the move will fail if all stats are maximized
/// </remarks>
[Script(ScriptCategory.Move, "acupressure")]
public class Acupressure : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var possibleStats = target.StatBoost.Where(x => x.statistic != Statistic.Hp && x.value < 6).ToArray();
        // If the target has no stats to raise, the move fails
        if (!possibleStats.Any())
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        var index = move.User.BattleData!.Battle.Random.GetInt(0, possibleStats.Length);
        var stat = possibleStats[index].statistic;
        target.ChangeStatBoost(stat, 2, false, false);
    }
}