namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "heal_percent")]
public class HealPercent : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
{
    private float _healPercent = 0.5f;

    /// <inheritdoc />
    public void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
    {
        if (parameters?.TryGetValue("healPercent", out var variable) == true && variable is float healPercent)
        {
            _healPercent = healPercent;
        }
    }

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var args = new CustomTriggers.ModifyHealPercentArgs(move, target, hit, _healPercent);
        move.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyHealPercent, args));
        var healPercent = args.HealPercent;

        target.Heal(target.BoostedStats.Hp.MultiplyOrMax(healPercent));
    }
}