namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Misty Surge is an ability that creates Misty Terrain when the Pokémon enters battle.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Misty_Surge_(Ability)">Bulbapedia - Misty Surge</see>
/// </summary>
[Script(ScriptCategory.Ability, "misty_surge")]
public class MistySurge : Script, IScriptOnSwitchIn
{
    /// <inheritdoc />
    public void OnSwitchIn(IPokemon pokemon, byte position)
    {
        if (pokemon.BattleData?.Battle is null)
            return;

        var terrainName = ScriptUtils.ResolveName<Terrain.MistyTerrain>();
        if (pokemon.BattleData.Battle.TerrainName == terrainName)
            return;

        EventBatchId batchId = new();
        pokemon.BattleData.Battle.EventHook.Invoke(new AbilityTriggerEvent(pokemon)
        {
            BatchId = batchId,
        });
        pokemon.BattleData.Battle.SetTerrain(terrainName, batchId);
    }
}