namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Magma Armor is an ability that prevents the Pokémon from being frozen.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Magma_Armor_(Ability)">Bulbapedia - Magma Armor</see>
/// </summary>
[Script(ScriptCategory.Ability, "magma_armor")]
public class MagmaArmor : Script, IScriptOnSwitchIn, IScriptPreventStatusChange
{
    /// <inheritdoc />
    public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
    {
        if (status == ScriptUtils.ResolveName<Status.Frozen>())
        {
            pokemon.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(pokemon));
            preventStatus = true;
        }
    }

    /// <inheritdoc />
    public void OnSwitchIn(IPokemon pokemon, byte position)
    {
        if (pokemon.HasStatus(ScriptUtils.ResolveName<Status.Frozen>()))
        {
            pokemon.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(pokemon));
            pokemon.ClearStatus();
        }
    }
}