namespace PkmnLib.Plugin.Gen7.Moves;

/// <summary>
/// The user helps the target and makes it use its move right after the user. 
/// </summary>
/// <remarks>
/// The target will move next on the current turn, ignoring priority. After You bypasses accuracy checks to always hit,
/// unless the target is in the semi-invulnerable turn of a move such as Dig or Fly. It fails if the target has already
/// moved on the same turn. After You ignores the effects of Quash.
/// After You fails if the order remains the same after using After You. 
/// </remarks>
[Script(ScriptCategory.Move, "after_you")]
public class AfterYou : Script
{
    /// <inheritdoc />
    public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var queue = move.User.BattleData!.Battle.ChoiceQueue;
        if (queue == null)
            return;
        
        // If the queue doesn't change, the move fails
        if (!queue.MovePokemonChoiceNext(target))
        {
            move.GetHitData(target, hit).Fail();
        }
    }
}