namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "skill_swap")]
public class SkillSwap : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var targetAbility = target.ActiveAbility;
        var userAbility = move.User.ActiveAbility;
        if (targetAbility == null || userAbility == null)
        {
            move.GetHitData(target, hit).Fail();
            return;
        }
        if (targetAbility.HasFlag("cant_be_changed") || userAbility.HasFlag("cant_be_changed"))
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        move.User.ChangeAbility(targetAbility);
        target.ChangeAbility(userAbility);
    }
}