using JetBrains.Annotations;
using UnityEngine;

namespace BehaviourTrees
{
    [RequireComponent(typeof(Blackboard))]
    public class BehaviourTree : MonoBehaviour
    {
        private Node root;

        public Node Root
        {
            get => root;
            protected set => root = value;
        }

        private Blackboard blackboard;

        [UsedImplicitly]
        private void Awake()
        {
            OnSetup();
            blackboard = GetComponent<Blackboard>();
        }

        [UsedImplicitly]
        // Update is called once per frame
        void Update()
        {
            root?.Evaluate(gameObject.transform, blackboard);
        }

        protected virtual void OnSetup()
        {
        }
    }
}