﻿using System;

namespace Yumon.Template.Lite.Internal
{
    /// <summary>
    ///     Simple state machine singleton for the Yumon Template Lite.
    ///     In the full version of this template, there are more states and they are scriptable objects
    ///     but the only states you need to worry about for the gameplay are the ones in this class.
    /// </summary>
    internal static class GameState
    {
        public static readonly State Home = new State(StateEnum.Home);
        public static readonly State Gameplay = new State(StateEnum.Gameplay);
        public static readonly State EndGame = new State(StateEnum.EndGame);

        static State s_currentState;

        static GameState()
        {
            CurrentState = Home;
        }
        public static State CurrentState
        {
            get => s_currentState;
            private set => SetState(value);
        }

        public static event Action<State> OnStateChange;

        public static void SetState(State value)
        {
            s_currentState?.onExit?.Invoke();
            s_currentState = value;
            s_currentState.onEnter?.Invoke();
            OnStateChange?.Invoke(value);
        }
    }
}
