using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class GameModeEvents : MonoBehaviour
{
    [Header("Reference")]
    [SerializeField]
    private GameModeReference Reference;

    [Header("Events")]
    public UnityEvent OnGameStart = new UnityEvent();
    public UnityEvent OnInputStart = new UnityEvent();
    public UnityEvent OnRoundStart = new UnityEvent();
    public UnityEvent OnPlayersMoved = new UnityEvent();
    public UnityEvent OnRoundEnd = new UnityEvent();
    public UnityEvent OnGameOver = new UnityEvent();


    private void OnEnable()
    {
        Reference.Value.GameStartEvent += GameStart;
        Reference.Value.InputStartEvent += (() => OnInputStart.Invoke());
        Reference.Value.RoundStartEvent += RoundStart;
        Reference.Value.AllPlayersMovedEvent += PlayersMoved;
        Reference.Value.RoundEndEvent += RoundEnd;
        Reference.Value.OnGameOverEvent += GameOver;
    }

    private void OnDisable()
    {
        Reference.Value.GameStartEvent -= GameStart;
        Reference.Value.InputStartEvent -= (() => OnInputStart.Invoke());
        Reference.Value.RoundStartEvent -= RoundStart;
        Reference.Value.AllPlayersMovedEvent -= PlayersMoved;
        Reference.Value.RoundEndEvent -= RoundEnd;
        Reference.Value.OnGameOverEvent -= GameOver;
    }

    private void GameStart()
    {
        OnGameStart.Invoke();
    }

    private void RoundStart()
    {
        OnRoundStart.Invoke();
    }

    private void PlayersMoved()
    {
        OnPlayersMoved.Invoke();
    }

    private void RoundEnd()
    {
        OnRoundEnd.Invoke();
    }
    private void GameOver()
    {
        OnGameOver.Invoke();
    }
}