using JetBrains.Annotations;
using PkmnLib.Plugin.Gen7.Scripts.Side;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "defog")]
public class Defog : Script, IScriptOnSecondaryEffect
{
    [PublicAPI] public static HashSet<StringKey> DefoggedEffects =
    [
        ScriptUtils.ResolveName<MistEffect>(),
        ScriptUtils.ResolveName<LightScreenEffect>(),
        ScriptUtils.ResolveName<ReflectEffect>(),
        ScriptUtils.ResolveName<SafeguardEffect>(),
        ScriptUtils.ResolveName<StickyWebEffect>(),
        ScriptUtils.ResolveName<SpikesEffect>(),
        "toxic_spikes",
        "stealth_rock",
    ];

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        if (target.BattleData == null)
            return;

        var targetSide = target.BattleData.Battle.Sides[target.BattleData.SideIndex];
        foreach (var effect in DefoggedEffects)
        {
            targetSide.VolatileScripts.Remove(effect);
        }
    }
}