using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SimplifyXR
{

    [DirectiveCategory(DirectiveCategories.Initiator,
        subCategory = DirectiveSubCategory.UI,
        directiveInfo = "This <i>initiator</i> starts a sequence when an <b>object anchor model is retained after alignment</b>.",
        prettyName = "Object Anchor Model Retained")]
    public class OnObjectAnchorModelRetained: Initiator
    {

        public ObjectAnchorPanelFeatures objectAnchorPanel;
        ObjectAnchorPanelFeatures objectAnchor;

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

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

        public new void Awake()
        {
            base.Awake();

            objectAnchorPanel =
                objectAnchorPanel == null ?
                Object.FindObjectOfType<ObjectAnchorPanelFeatures>() :
                objectAnchorPanel;


            objectAnchor = objectAnchorPanel.GetComponentInChildren<ObjectAnchorPanelFeatures>();

            objectAnchor?.ObjectAnchorModelRetained
                .AddListener(HandleObjectAnchorRetained);
        }

        public new void OnDestroy()
        {
            base.OnDestroy();
            objectAnchor?.ObjectAnchorModelRetained
                .RemoveListener(HandleObjectAnchorRetained);
        }

        public void HandleObjectAnchorRetained()
        {
            base.Initiate();
        }
    }
}