namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;

[Script(ScriptCategory.Pokemon, "slow_start")]
public class SlowStartEffect : Script, IScriptChangeSpeed, IScriptChangeOffensiveStatValue, IScriptOnEndTurn
{
    private int _turnsRemaining = 5;

    /// <inheritdoc />
    public void ChangeSpeed(ITurnChoice choice, ref uint speed)
    {
        speed /= 2;
    }

    /// <inheritdoc />
    public void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat,
        ImmutableStatisticSet<uint> targetStats, Statistic stat, ref uint value)
    {
        if (stat == Statistic.Attack)
            value /= 2;
    }

    /// <inheritdoc />
    public void OnEndTurn(IScriptSource owner, IBattle battle)
    {
        if (_turnsRemaining <= 0)
            return;
        _turnsRemaining--;
        if (_turnsRemaining == 0)
        {
            RemoveSelf();
        }
    }
}