#if USING_MRTK3 

using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Subsystems;
using UnityEngine;
using UnityEngine.Events;

namespace SimplifyXR
{
    public class MRTK3SpeechHandlerMapping : MonoBehaviour, ISpeechHandlerMapping
    {
#if USING_MRTK3Speech
        KeywordRecognitionSubsystem subsystem;
#endif


        void Start()
        {
#if USING_MRTK3Speech

            // Get the first running keyword recognition subsystem.
            subsystem = XRSubsystemHelpers.GetFirstRunningSubsystem<KeywordRecognitionSubsystem>();
#endif

        }

        public void RegisterHandler(string key, UnityAction handler)
        {
#if USING_MRTK3Speech

            if (subsystem != null)
            {
                subsystem.CreateOrGetEventForKeyword(key).AddListener(handler);
            }
            else
            {
                Debug.LogError("Cannot register as keyword subsytem is null");
            }
#endif


        }
        public void UnregisterHandler(string key, UnityAction handler)
        {
            #if USING_MRTK3Speech

            if (subsystem != null)
            {
                subsystem.CreateOrGetEventForKeyword(key).RemoveListener(handler);
            }
            else
            {
                Debug.LogError("Cannot unregister as keyword subsytem is null");
            }
#endif
        }

    }
}

#endif
