namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;

[Script(ScriptCategory.Pokemon, "heal_each_end_of_turn_effect")]
public class HealEachEndOfTurnEffect : Script, IScriptOnEndTurn
{
    private readonly float _healPercentage;
    private readonly IPokemon? _pokemon;

    private HealEachEndOfTurnEffect()
    {
    }

    public HealEachEndOfTurnEffect(float healPercentage, IPokemon pokemon)
    {
        _healPercentage = healPercentage;
        _pokemon = pokemon;
    }

    /// <param name="owner"></param>
    /// <param name="battle"></param>
    /// <inheritdoc />
    public void OnEndTurn(IScriptSource owner, IBattle battle)
    {
        if (_pokemon is null)
            return;
        if (_pokemon.BattleData?.IsOnBattlefield != true)
            return;

        var amount = _pokemon.BoostedStats.Hp * _healPercentage;
        if (_pokemon.HasHeldItem("big_root"))
            amount *= 1.3f;
        _pokemon.Heal((uint)amount);
    }
}