using Cirno.Scripts.Components.FSM.Player;
using Godot;

namespace Cirno.Scripts.Resources.ItemEffects;

[GlobalClass]
[Tool]
public partial class HealPercentEffectResource : ItemEffectResource
{
    [Export] public float HealPercentage = 25f;
    [Export] public HealEffectResource.HealResourceType ResourceType { get; private set; } = HealEffectResource.HealResourceType.Health;
    public override IITemEffectMachine Execute(PlayerFSMItemUseModule parent, LootItem item)
    {
        return new HealPercentEffectMachine(this, parent, item).Execute();
    }
    
    public class HealPercentEffectMachine(HealPercentEffectResource resource, PlayerFSMItemUseModule parent, LootItem item) : IITemEffectMachine
    {
        public IITemEffectMachine Execute()
        {
            switch (resource.ResourceType)
            {
                case HealEffectResource.HealResourceType.Health:
                    parent.Health.CurrentResource += Mathf.CeilToInt(parent.Health.MaxResource * resource.HealPercentage / 100);
                    break;
                case HealEffectResource.HealResourceType.Shield:
                    parent.Shield.CurrentResource += Mathf.CeilToInt(parent.Shield.MaxResource * resource.HealPercentage / 100);
                    break;
            }

            return this;
        }
    }
}