namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

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

        if (userAbility.HasFlag("cant_be_copied") || targetAbility?.HasFlag("cant_be_changed") != false)
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        target.ChangeAbility(userAbility);
    }
}