using PkmnLib.Dynamic.ScriptHandling;

namespace PkmnLib.Dynamic.Models.Choices;

/// <summary>
/// The choice of a Pokémon to use a move.
/// </summary>
public interface IMoveChoice : ITurnChoice
{
    /// <summary>
    /// The move that is used.
    /// </summary>
    ILearnedMove UsedMove { get; }

    /// <summary>
    /// The side the move is targeted at.
    /// </summary>
    byte TargetSide { get; }

    /// <summary>
    /// The position the move is targeted at.
    /// </summary>
    byte TargetPosition { get; }

    /// <summary>
    /// The priority of the move.
    /// </summary>
    sbyte Priority { get; set; }

    /// <summary>
    /// The underlying script of the move.
    /// </summary>
    ScriptContainer Script { get; set; }
}

/// <inheritdoc cref="IMoveChoice"/>
public class MoveChoice : TurnChoice, IMoveChoice
{
    /// <inheritdoc cref="MoveChoice"/>
    public MoveChoice(IPokemon user, ILearnedMove usedMove, byte targetSide, byte targetPosition) : base(user)
    {
        UsedMove = usedMove;
        TargetSide = targetSide;
        TargetPosition = targetPosition;
    }

    /// <inheritdoc />
    public ILearnedMove UsedMove { get; }

    /// <inheritdoc />
    public byte TargetSide { get; }

    /// <inheritdoc />
    public byte TargetPosition { get; }

    /// <inheritdoc />
    public sbyte Priority { get; set; }

    /// <inheritdoc />
    public ScriptContainer Script { get; set; } = new();

    /// <inheritdoc />
    public override int ScriptCount => 1 + User.ScriptCount;

    /// <inheritdoc />
    public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts) => scripts.Add(Script);

    /// <inheritdoc />
    public override void CollectScripts(List<IEnumerable<ScriptContainer>> scripts)
    {
        GetOwnScripts(scripts);
        User.CollectScripts(scripts);
    }
}