using PkmnLib.Static.Moves;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "pollen_puff")]
public class PollenPuff : Script, IScriptOnSecondaryEffect, IScriptChangeCategory
{
    /// <inheritdoc />
    /// <inheritdoc />
    public void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
    {
        var battleData = move.User.BattleData;
        var targetBattleData = target.BattleData;

        if (battleData == null || targetBattleData == null)
            return;

        if (battleData.SideIndex == targetBattleData.SideIndex)
        {
            category = MoveCategory.Status;
        }
    }

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var battleData = move.User.BattleData;
        var targetBattleData = target.BattleData;

        if (battleData == null || targetBattleData == null)
            return;

        if (battleData.SideIndex == targetBattleData.SideIndex)
        {
            var maxHealth = target.MaxHealth;
            target.Heal(maxHealth / 2);
        }
    }
}