namespace Darkmatter.Libs.FSM
{
    public abstract class StateMachine
    {
        public IState CurrentState { get; private set; }
        public IState PreviousState { get; private set; }

        public void ChangeState(IState newState)
        {
            if (newState == null) return;
            if (CurrentState == newState) return; 

            CurrentState?.Exit();

            PreviousState = CurrentState;
            CurrentState = newState;

            CurrentState.Enter();
        }

        public virtual void Tick()
        {
            CurrentState?.Tick();
        }
    }
}