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

namespace Cirno.Scripts.Resources.ItemEffects;

[GlobalClass]
[Tool]
public partial class ResourceIncreaseEffectResource : ItemEffectResource
{
    [Export] public float IncreaseAmount { get; private set; } = 4f;
    [Export] public HealEffectResource.HealResourceType ResourceType { get; private set; } = HealEffectResource.HealResourceType.Health;
    
    public override IITemEffectMachine Execute(PlayerFSMItemUseModule parent, LootItem item)
    {
        return new ResourceIncreaseMachine(this, parent, item).Execute();
    }

    public class ResourceIncreaseMachine(
        ResourceIncreaseEffectResource resource,
        PlayerFSMItemUseModule parent,
        LootItem item) : IITemEffectMachine
    {
        public IITemEffectMachine Execute()
        {
            switch (resource.ResourceType)
            {
                case HealEffectResource.HealResourceType.Health:
                    parent.Health.MaxResource += resource.IncreaseAmount;
                    break;
                case HealEffectResource.HealResourceType.Shield:
                    parent.Shield.MaxResource += resource.IncreaseAmount;
                    break;
            }
            return this;
        }
    }
}