namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "change_all_target_stats")]
public class ChangeAllTargetStats : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
{
    private sbyte _amount;

    /// <inheritdoc />
    public void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
    {
        if (parameters == null)
        {
            throw new ArgumentNullException(nameof(parameters));
        }
        if (!parameters.TryGetValue("amount", out var amount) || amount == null)
        {
            throw new ArgumentException("Parameter 'amount' is required.");
        }
        _amount = (sbyte)(int)amount;
    }

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        target.ChangeStatBoost(Statistic.Attack, _amount, target == move.User, false);
        target.ChangeStatBoost(Statistic.Defense, _amount, target == move.User, false);
        target.ChangeStatBoost(Statistic.SpecialAttack, _amount, target == move.User, false);
        target.ChangeStatBoost(Statistic.SpecialDefense, _amount, target == move.User, false);
        target.ChangeStatBoost(Statistic.Speed, _amount, target == move.User, false);
    }
}