using UnityEngine;
using UnityEngine.Events;
using static UnityEngine.InputSystem.InputAction;

namespace KitsuneCafe.Entity
{
    public interface IInputProvider
    {
        Vector2 MovementDirection { get;  }
        bool Sprinting { get;  }
        bool Interacting { get;  }
    }
    
    public class Input : MonoBehaviour
    {
        [SerializeField]
        private UnityEvent<Vector2> OnMove;

        [SerializeField]
        private UnityEvent<bool> OnSprint;

        [SerializeField]
        private UnityEvent OnInteract;

        public void HandleMove(CallbackContext context)
        {
            if (context.performed)
            {
                OnMove.Invoke(context.ReadValue<Vector2>());
            }
            else if (context.canceled)
            {
                OnMove.Invoke(Vector2.zero);
            }
        }

        public void HandleSprint(CallbackContext context)
        {
            OnSprint.Invoke(context.ReadValueAsButton());
        }

        public void HandleInteract(CallbackContext context)
        {
            if (context.ReadValueAsButton())
            {
                OnInteract.Invoke();
            }
        }
    }
}
