using TMPro;
using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public enum GameState
    {
        Paused,
        Playing,
        GameOver,
        Won
    }

    public static GameManager gameManagerInstance { get; private set; }

    [SerializeField] int currentOrbCounter = 0;
    [SerializeField] int maximumOrbs = 10;

    [SerializeField] TextMeshProUGUI orbCounterText;

    public GameState gameState = GameState.Playing;

    
    private void Awake()
    {
        if(gameManagerInstance == null)
        {
            gameManagerInstance = this;

            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
            return;
        }
    }

    private void Update()
    {
        if(gameState == GameState.GameOver)
        {
            SceneManager.LoadScene("GameOverScene");
        }
    }

    public void IncreaseOrbCounter()
    {
        currentOrbCounter++;
        orbCounterText.text = currentOrbCounter.ToString();
        checkAllOrbsCollected(currentOrbCounter);
    }

    private void checkAllOrbsCollected(int currentOrbCounter)
    {
        if(currentOrbCounter == maximumOrbs)
        {
            gameState = GameState.Won;
            Debug.Log("Player won! All orbs were collected!");

            SceneManager.LoadScene("VictoryScene");
        }
    }
}
