namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;

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

    public LeechSeedEffect(IPokemon owner, IPokemon placer)
    {
        _owner = owner;
        _placer = placer;
    }

    /// <inheritdoc />
    public void OnEndTurn(IScriptSource owner, IBattle battle)
    {
        var damage = _owner.MaxHealth / 8;
        if (_owner.CurrentHealth <= damage)
            damage = _owner.CurrentHealth;

        _owner.Damage(damage, DamageSource.Misc);
        if (_owner.ActiveAbility?.Name == "liquid_ooze")
            _placer.Damage(damage, DamageSource.Misc);
        else
            _placer.Heal(damage);
    }

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