namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "guard_swap")]
public class GuardSwap : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        EventBatchId eventBatchId = new();

        var user = move.User;
        var userStats = user.StatBoost;
        var targetStats = target.StatBoost;

        var userDefense = userStats.GetStatistic(Statistic.Defense);
        var targetDefense = targetStats.GetStatistic(Statistic.Defense);
        var userSpecialDefense = userStats.GetStatistic(Statistic.SpecialDefense);
        var targetSpecialDefense = targetStats.GetStatistic(Statistic.SpecialDefense);

        user.ChangeStatBoost(Statistic.Defense, (sbyte)(targetDefense - userDefense), true, true, eventBatchId);
        user.ChangeStatBoost(Statistic.SpecialDefense, (sbyte)(targetSpecialDefense - userSpecialDefense), true, true,
            eventBatchId);
        target.ChangeStatBoost(Statistic.Defense, (sbyte)(userDefense - targetDefense), false, true, eventBatchId);
        target.ChangeStatBoost(Statistic.SpecialDefense, (sbyte)(userSpecialDefense - targetSpecialDefense), false,
            true, eventBatchId);
    }
}