using UnityEngine;

namespace MaskShop
{
    /// <summary>
    /// Simple GameManager singleton for controlling game state
    /// This is a basic implementation - expand as needed for your game
    /// </summary>
    public class GameManager : MonoBehaviour
    {
        private static GameManager instance;
        public static GameManager Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = FindObjectOfType<GameManager>();

                    if (instance == null)
                    {
                        GameObject go = new GameObject("GameManager");
                        instance = go.AddComponent<GameManager>();
                    }
                }
                return instance;
            }
        }

        [Header("Game State")]
        public bool gameStarted = false;

        [Header("Debug")]
        [SerializeField] private bool showDebugInfo = true;
        internal bool hasSeenIntro;

        private void Awake()
        {
            if (instance == null)
            {
                instance = this;
                DontDestroyOnLoad(gameObject);
            }
            else if (instance != this)
            {
                Destroy(gameObject);
            }
        }

        /// <summary>
        /// Inicia el juego
        /// </summary>
        [ContextMenu("Start Game")]
        public void StartGameplay()
        {
            gameStarted = true;

            if (showDebugInfo)
            {
                Debug.Log("GameManager: Game Started!");
            }
        }

        /// <summary>
        /// Detiene el juego
        /// </summary>
        [ContextMenu("Stop Game")]
        public void StopGame()
        {
            gameStarted = false;

            if (showDebugInfo)
            {
                Debug.Log("GameManager: Game Stopped!");
            }
        }

        /// <summary>
        /// Alterna el estado del juego
        /// </summary>
        public void ToggleGameState()
        {
            gameStarted = !gameStarted;

            if (showDebugInfo)
            {
                Debug.Log($"GameManager: Game state toggled to {(gameStarted ? "Started" : "Stopped")}");
            }
        }
    }
}