using PkmnLib.Dynamic.ScriptHandling;

namespace PkmnLib.Dynamic.Models.Choices;

/// <summary>
/// A choice to flee from a battle.
/// </summary>
public interface IFleeChoice : ITurnChoice
{
}

/// <inheritdoc cref="IFleeChoice"/>
public class FleeTurnChoice : TurnChoice, IFleeChoice
{
    /// <inheritdoc />
    public FleeTurnChoice(IPokemon user) : base(user)
    {
    }

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

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

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

    /// <inheritdoc />
    public override string ToString() => $"FleeChoice: {User}";

    protected bool Equals(FleeTurnChoice other) => other.User == User;

    /// <inheritdoc />
    public override bool Equals(object? obj)
    {
        if (obj is null)
            return false;
        if (ReferenceEquals(this, obj))
            return true;
        if (obj is not FleeTurnChoice other)
            return false;
        return Equals(other);
    }

    /// <inheritdoc />
    public override int GetHashCode() =>
        // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
        User?.GetHashCode() ?? 0;
}