using UnityEngine.Events;
using VOID.Generic.Objects.Abstract.Events;

namespace VOID.Generic.AI.Schema
{
    public class SchemaUnitEventWrapper<TUnitEvent, TMemory> where TUnitEvent : AbstractEvent
    {
        private UnityEvent<TUnitEvent> _listener;
        private UnityAction<TUnitEvent> _action;

        public SchemaUnitEventWrapper(
            UnityEvent<TUnitEvent> addListenerTo,
            UnityAction<TUnitEvent, TMemory, UnitObjectSchemaAgent> action,
            UnitObjectSchemaAgent agent,
            TMemory memory)
        {
            _listener = addListenerTo;
            _action = t1 => action.Invoke(t1, memory, agent);
        }

        public void On()
        {
            _listener.AddListener(_action);
        }

        public void Off()
        {
            _listener.RemoveListener(_action);
        }
    }
}