using System;
using System.Collections.Generic;
using PkmnLib.Static;
using PkmnLib.Static.Utils;

namespace PkmnLib.Dynamic.Events;

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

    /// <inheritdoc />
    public override 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 override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        target.ChangeStatBoost(Statistic.Attack, _amount, target == move.User);
        target.ChangeStatBoost(Statistic.Defense, _amount, target == move.User);
        target.ChangeStatBoost(Statistic.SpecialAttack, _amount, target == move.User);
        target.ChangeStatBoost(Statistic.SpecialDefense, _amount, target == move.User);
        target.ChangeStatBoost(Statistic.Speed, _amount, target == move.User);
    }
}