using System.Collections.Generic;
using Intrepid.Core.Entities;
using Intrepid.Core.Tags;
using Intrepid.GameManagers;
using Intrepid.Gameplay.Journey.Runtime.Events;
using Intrepid.Utilities;
using UnityEngine;

namespace Intrepid.Gameplay.Prototyping.Sockets
{
    public class StageSocketChangeTrigger : EntityTrigger
    {
        [GroupInjections, SerializeField] private InteractableSocketModelPrototype socket;

        private BoxCollider BoxCollider => MainCollider as BoxCollider;
        
        protected override void WhenRaiseEnterEvent(Collider other, EntitySensor entitySensor, List<BehaviourTag> behaviourTags)
        {
            Proxy.Instance.EventBus.Raise(new StageSocketChangeEnterEvent
            {
                StageTag = socket.StageTag,
                EndpointId = socket.EndpointId,
            });
        }

        protected override void WhenRaiseExitEvent(Collider other, EntitySensor entitySensor)
        {
            Proxy.Instance.EventBus.Raise(new StageSocketChangeExitEvent
            {
                StageTag = socket.StageTag,
                EndpointId = socket.EndpointId,
            });
        }
        
#if UNITY_EDITOR
        private void OnDrawGizmos()
        {
            if (BoxCollider is null)
            {
                return;
            }
            Gizmos.color = Color.yellow;
            Gizmos.DrawWireCube(BoxCollider.bounds.center, BoxCollider.bounds.size);
        }
#endif
    }
}