using System;
using Intrepid.FSM;
using Intrepid.GameManagers;
using Intrepid.SimpleEvents;
using Intrepid.Structures;
using Intrepid.Utilities;
using UnityEngine;

namespace Intrepid.Core.Entities
{
    public abstract class EntityState<TKey, TImplementation> : Identification, IState<TKey, TImplementation> where TKey: IComparable
    {
        [GroupConfigurations, SerializeField] private bool startState;

        public bool IsStartState => startState;
        
        public abstract bool CanEnterState { get; }
        public abstract bool CanExitState { get; }
        public abstract TKey GetStateKey();
        public abstract TImplementation Implementation();
        protected abstract void Subscriptions();
        protected abstract void RunOnEnter(ParameterStore ps);
        protected abstract void RunOnExit();

        protected void Subscribe<TEvent>(Action<TEvent> action) where TEvent : IEventBase
        {
            Proxy.Instance.EventBus.Subscribe(Id, action);
        }

        public virtual void OnEnterState(ParameterStore ps)
        {
            Subscriptions();
            RunOnEnter(ps);
        }

        public virtual void OnExitState()
        {
            RunOnExit();
            Proxy.Instance.EventBus.UnSubscribe(Id);
        }
    }
}