using UnityEngine;
using VOID.Generic.Objects.Abstract;
using VOID.Generic.Objects.Unit;
using VOID.Generic.Triggers;

namespace VOID.Generic.Objects.Door.State
{
    public class DoorOpenerTrigger : MonoBehaviour, IDynamicTrigger
    {
        #region ParentGetterSetter

        private DoorObject _door;
        public DoorObject door
        {
            get => _door;
            set
            {
                if (!_door) _door = value;
                else Debug.LogWarning("Trying to set parent object " + _door.name + " again.");
            }
        }

        #endregion
        
        public void OnObjectEnter(AbstractObject obj)
        {
            if (obj is UnitObject && !door.doorState.isOpen) door.Open();
        }

        public void OnObjectExit(AbstractObject obj)
        {
        }
    }
}