using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class EventManager : MonoBehaviour
{
    public static EventManager Instance { get; private set; }

    public Action onTick;

    public Action<Sprite> onStress;
    public Action<Transformation> onTransformation;
    public Action onGameOver;

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

    private void Start()
    {
        Debug.Log("Ticktime: " +GameManager.Instance.TickTime);
       
    }

    private void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            SceneManager.LoadScene(0);
        }
    }

    public void StartTick()
    {
        InvokeRepeating("Tick", 3, GameManager.Instance.TickTime);
    }

    public void CancelTick()
    {
        CancelInvoke("Tick");
    }


    public void Tick()
    {
        onTick?.Invoke();
    }

    public void Stress(Sprite negativeEffectSprite)
    {
        onStress?.Invoke(negativeEffectSprite);
    }

    public void Transformation(Transformation transformMode)
    {
        onTransformation?.Invoke(transformMode);
    }

    public void GameOver()
    {
        onGameOver?.Invoke();
    }
}