using MackySoft.SerializeReferenceExtensions;
using UnityEngine;

namespace Gyvr.Mythril2D
{
    public class Waypoint : MonoBehaviour
    {
        public float pauseDuration = 0.0f;
        public bool roamAtWaypoint = false;
        public bool executeCommandOnce = true;
        [SerializeReference, SubclassSelector] private ICommand m_executeAtWaypoint = null;

        private bool hasExecutedCommand = false;

        public ICommand executeAtWaypoint => m_executeAtWaypoint;

        public void ExecuteWaypointCommand()
        {
            if (m_executeAtWaypoint == null) { return; }

            if (executeCommandOnce && !hasExecutedCommand)
            {
                m_executeAtWaypoint?.Execute();
                hasExecutedCommand = true;
            }
            else if (!executeCommandOnce)
            {
                m_executeAtWaypoint?.Execute();
            }
        }
    }
}
