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

namespace Cirno.Scripts.Resources.ItemEffects;

[GlobalClass]
[Tool]
public partial class HealEffectResource : ItemEffectResource
{
    [Export] public float HealAmount { get; private set; } = 10f;
    [Export] public HealResourceType ResourceType { get; private set; } = HealResourceType.Health;

    public override IITemEffectMachine Execute(PlayerFSMItemUseModule parent, LootItem item)
    {
        return new HealEffectMachine(this, parent, item).Execute();
    }

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

    public enum HealResourceType
    {
        Health,
        Shield
    }
}