using System;
using UnityEngine;

public sealed class StateMachine : MonoBehaviour
{
    [SerializeField]
    private AbstractState[] states = Array.Empty<AbstractState>();
    [SerializeField]
    private AbstractState currentState = null;

    public AbstractState Current => currentState;

    private void Start()
    {
        foreach (var state in states)
        {
            if (state != null)
            {
                state.Init(this);
                state.ExitState();
            }
        }
        if (currentState != null)
            currentState.EnterState();
    }

    public void SetState(AbstractState state = null) {
        if (currentState != null)
            currentState.ExitState();

        currentState = state;

        if (currentState != null)
            currentState.EnterState();
    }
}
