using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Static.Species;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

/// <summary>
/// If it is the opposite gender of the user, the target becomes infatuated and less likely to attack. 
/// </summary>
/// <remarks>
/// The target becomes infatuated with the user if they have opposite genders. Attract works regardless of type immunity.
/// Unlike most status moves, Attract is able to bypass a substitute.
/// Attract has no effect if the user and target have the same gender, or if either of them is a gender-unknown Pokémon
/// (such as Magnemite). It also fails when used on a Pokémon that is already infatuated.
/// Pokémon with the Ability Oblivious or under the protection of Aroma Veil are immune to the effects of Attract. If
/// a Pokémon is infatuated by Attract while holding a Mental Herb or an Eggant Berry, the item will be consumed and the
/// infatuation will end. Even if the Pokémon has Oblivious, the item will still be consumed.
/// If the target Pokémon becomes infatuated while holding a Destiny Knot, the user will also become infatuated with the
/// target. 
/// </remarks>
[Script(ScriptCategory.Move, "attract")]
public class Attract : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        if (target.Gender == move.User.Gender)
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        if (target.Gender == Gender.Genderless || move.User.Gender == Gender.Genderless)
        {
            move.GetHitData(target, hit).Fail();
            return;
        }
        if (target.Volatile.Contains("infatuated"))
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        target.Volatile.Add(new Infatuated());
    }
}