namespace PkmnLib.Plugin.Gen7.Scripts.Side;

[Script(ScriptCategory.Side, "flower_veil")]
public class FlowerVeilEffect : Script, IScriptPreventStatBoostChange, IScriptPreventStatusChange
{
    private readonly HashSet<IPokemon> _placerPokemon = [];

    public void OnAdded(IPokemon placer)
    {
        _placerPokemon.Add(placer);
    }

    public void OnRemoved(IPokemon placer)
    {
        _placerPokemon.Remove(placer);
        if (_placerPokemon.Count == 0)
        {
            RemoveSelf();
        }
    }

    /// <inheritdoc />
    public void PreventStatBoostChange(IPokemon target, Statistic stat, sbyte amount, bool selfInflicted,
        ref bool prevent)
    {
        if (selfInflicted)
            return;

        if (amount > 0)
            return;

        if (target.Types.All(x => x.Name != "grass"))
            return;

        prevent = true;
    }

    /// <inheritdoc />
    public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
    {
        if (selfInflicted)
            return;
        if (pokemon.Types.All(x => x.Name != "grass"))
            return;

        preventStatus = true;
    }
}