﻿#if USING_MRTK2

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using System.Reflection;
using System.Linq;
using System;
using Microsoft.MixedReality.Toolkit.Utilities.Solvers;

namespace SimplifyXR
{
    /// <summary>
    /// Sends the manipulation event data from a unity event
    /// </summary>
    [DirectiveCategory(DirectiveCategories.Initiator, DirectiveSubCategory.UserInteraction, 
        DirectiveLibrary.MRTK2, "Tap to Place",
        directiveInfo ="This initiator starts a sequence when a <b>MRTK TapToPlace</b> object is <b>placed.</b>")]
    public class MRTKTapToPlaceInitiator : EventInitiator
    {
        [Required, Tooltip("The object with a tap to place component"), SceneTip]
        public TapToPlace objectToPlace;

        [CustomEvent("objectToPlace")]
        public string eventFieldInfoName;
     

        public override List<KnobKeywords> ReceiveKeywords()
        {
            return new List<KnobKeywords>();
        }

        public override List<KnobKeywords> SendKeywords()
        {
            return new List<KnobKeywords>(){
                new KnobKeywords("ObjectPlaced", typeof(GameObject)),
            };
        }

        protected new void Awake()
        {
            base.Awake();
            if(enabled) RegisterEvents(eventFieldInfoName, objectToPlace, SingleTypeInitiate);          
        }       


        protected new void OnDestroy()
        {
            UnregisterEvents(eventFieldInfoName, objectToPlace, SingleTypeInitiate);
            base.OnDestroy();
        }
        public void SingleTypeInitiate()
        {
            SendData();
            base.Initiate();
        }
        void SendData()
        {
            var thisData = new List<object> { objectToPlace.gameObject };
            var thisKeywords = new List<string> { "ObjectPlaced" };
            AddPassableData(thisKeywords, thisData);
        }


    }

}

#endif
