using PkmnLib.Plugin.Gen7.Scripts.Pokemon;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "infestation")]
public class Infestation : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var infestationEffect = ScriptUtils.ResolveName<InfestationEffect>();
        if (target.Volatile.Contains(infestationEffect))
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        var battleData = move.User.BattleData;
        if (battleData == null)
            return;

        var turns = 4;
        if (battleData.Battle.Random.GetBool())
        {
            turns = 5;
        }
        target.Volatile.Add(new InfestationEffect(target, turns));
    }
}