using PkmnLib.Plugin.Gen7.Scripts.Status;

namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;

[Script(ScriptCategory.Pokemon, "nightmare")]
public class NightmareEffect : Script, IScriptOnEndTurn, IAIInfoScriptExpectedEndOfTurnDamage
{
    private readonly IPokemon _owner;

    public NightmareEffect(IPokemon owner)
    {
        _owner = owner;
    }

    /// <inheritdoc />
    public void OnEndTurn(IScriptSource owner, IBattle battle)
    {
        if (!_owner.HasStatus(ScriptUtils.ResolveName<Sleep>()))
        {
            RemoveSelf();
            return;
        }
        var maxHp = _owner.MaxHealth;
        _owner.Damage(maxHp / 4, DamageSource.Misc);
    }

    /// <inheritdoc />
    public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
    {
        damage += (int)(_owner.MaxHealth / 4f);
    }
}