using PkmnLib.Plugin.Gen7.Scripts.Pokemon;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

/// <summary>
/// Implements the secondary effect of Thrash, which forces the user to continue using the move for 2-3 turns,
/// then confuses the user.
/// </summary>
[Script(ScriptCategory.Move, "thrash")]
public class Thrash : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        if (move.User.Volatile.Contains<ThrashEffect>())
            return;

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

        var turns = battleData.Battle.Random.GetBool() ? 2 : 3;
        move.User.Volatile.Add(new ThrashEffect(move.User, turns, move.MoveChoice.TargetSide,
            move.MoveChoice.TargetPosition));
    }
}