namespace PkmnLib.Plugin.Gen7.Scripts.Side;

[Script(ScriptCategory.Side, "sea_of_fire_effect")]
public class SeaOfFireEffect : Script, IScriptOnEndTurn
{
    private int _turns = 5;

    /// <inheritdoc />
    public void OnEndTurn(IScriptSource owner, IBattle battle)
    {
        if (owner is not IBattleSide side)
            return;
        _turns--;
        if (_turns <= 0)
        {
            RemoveSelf();
            return;
        }

        foreach (var pokemon in side.Pokemon.WhereNotNull())
        {
            if (pokemon.Types.Any(x => x.Name == "fire"))
                continue;

            pokemon.Damage(pokemon.MaxHealth / 8, DamageSource.Misc);
        }
    }
}