#if USING_MRTK2

using UnityEngine;
using UnityEngine.Events;

namespace SimplifyXR
{

    [RequireComponent(typeof(MRTK2SpeechHandlerWrapper))]
    public class MRTK2SpeechHandlerMapping : MonoBehaviour, ISpeechHandlerMapping
    {
        private MRTK2SpeechHandlerWrapper handler;

        void Awake()
        {
            SetupHandler(); 
        }

        private void SetupHandler()
        {
            if (handler == null)
            {
                handler = GetComponent<MRTK2SpeechHandlerWrapper>();
                //responses are global, and the logic for handling focus is at panel level through register/unregister
                handler.SetFocus(false);
            }
        }


        //NOTE: YOUR PHRASE MUST BE ADDED TO THE MRTK CONFIG PROFLE IN ORDER TO BE REGISTERED
        //SUCCESSFUL KEYWORD/REPOSNSE WILL ALSO NOT SHOW UP IN INSPECTOR FOR WRAPPER OBJECT
        public void RegisterHandler(string phrase, UnityAction handleEvent)
        {
            SetupHandler();
            handler.AddResponse(phrase, handleEvent);
        }

        public void UnregisterHandler(string phrase, UnityAction handleEvent)
        {
            SetupHandler(); 
            handler.RemoveResponse(phrase, handleEvent);
        }
    }

}

#endif
