using KitsuneCafe.System;
using UnityEngine;
using UnityEngine.Events;

namespace KitsuneCafe.Interaction
{
    public class Interactable : MonoBehaviour, IInteractable
    {
        [SerializeField]
        private bool oneTimeUse = false;

        [SerializeField]
        private UnityEvent<IInteractor> onInteracted = default;

        private bool isInteractable = true;

        public bool IsInteractable => isInteractable;

        public IResult<Unit, InteractionError> Interact(IInteractor interactor)
        {
            onInteracted.Invoke(interactor);

            if (oneTimeUse)
            {
                isInteractable = false;
            }

            return Result.Ok<Unit, InteractionError>(default);
        }

        public void SetInteractable(bool interactable = true)
        {
            isInteractable = interactable;
        }
    }
}
