using UnityEngine;
using System.Collections;

public class AudioManager : MonoBehaviour {

    public GameObject SFX_Combo, SFX_Correct, SFX_Incorrect, SFX_Fail, SFX_Success, SFX_Warning, SFX_Countdown, SFX_ComboTimer, SFX_ButtonClick;

    #region Message Event Listeners
    void OnEnable()
    {
        EventManager.StartListening(Constants.GenerateCombo, PlaySFX_Combo);
        EventManager.StartListening(Constants.CorrectInput, PlaySFX_Correct);
        EventManager.StartListening(Constants.IncorrectInput, PlaySFX_Incorrect);
        EventManager.StartListening(Constants.CombinationFailed, PlaySFX_Failed);
        EventManager.StartListening(Constants.CombinationSuccessful, PlaySFX_Success);
        EventManager.StartListening(Constants.StartTimer, PlaySFX_Countdown);
        EventManager.StartListening(Constants.Warning, PlaySFX_Warning);
        EventManager.StartListening(Constants.ComboTimerRunning, PlaySFX_ComboTimer);
        EventManager.StartListening(Constants.GAME_OVER, StopAllFX);
        EventManager.StartListening(Constants.ButtonClick, PlaySFX_ButtonClick);
    }

    void OnDisable()
    {
        EventManager.StopListening(Constants.GenerateCombo, PlaySFX_Combo);
        EventManager.StopListening(Constants.CorrectInput, PlaySFX_Correct);
        EventManager.StopListening(Constants.IncorrectInput, PlaySFX_Incorrect);
        EventManager.StopListening(Constants.CombinationFailed, PlaySFX_Failed);
        EventManager.StopListening(Constants.CombinationSuccessful, PlaySFX_Success);
        EventManager.StopListening(Constants.StartTimer, PlaySFX_Countdown);
        EventManager.StopListening(Constants.Warning, PlaySFX_Warning);
        EventManager.StopListening(Constants.ComboTimerRunning, PlaySFX_ComboTimer);
        EventManager.StopListening(Constants.GAME_OVER, StopAllFX);
        EventManager.StopListening(Constants.ButtonClick, PlaySFX_ButtonClick);
    }
    #endregion
    
    void playAudio(GameObject SFX)
    {
        AudioSource audioSource = SFX.GetComponent<AudioSource>();
        audioSource.Play();
    }

    void stopAudio(GameObject SFX) 
    {
        AudioSource audioSource = SFX.GetComponent<AudioSource>();
        audioSource.Stop();
    }

    void PlaySFX_Correct() 
    {
        playAudio(SFX_Correct);
    }

    void PlaySFX_Incorrect()
    {
        playAudio(SFX_Incorrect);
    }

    void PlaySFX_Success()
    {
        playAudio(SFX_Success);
    }

    void PlaySFX_Failed()
    {
        playAudio(SFX_Fail);
    }

    void PlaySFX_Combo()
    {
        playAudio(SFX_Combo);
    }

    void PlaySFX_Warning()
    {
        playAudio(SFX_Warning);
    }

    void PlaySFX_Countdown() 
    {
        playAudio(SFX_Countdown);
    }

    void PlaySFX_ComboTimer() 
    {
        playAudio(SFX_ComboTimer);
    }

    void PlaySFX_ButtonClick() 
    {
        playAudio(SFX_ButtonClick);
    }

    void StopAllFX() 
    {
        stopAudio(SFX_Combo);
        stopAudio(SFX_ComboTimer);
        stopAudio(SFX_Correct);
        stopAudio(SFX_Countdown);
        stopAudio(SFX_Fail);
        stopAudio(SFX_Incorrect);
        stopAudio(SFX_Success);
        stopAudio(SFX_Warning);
    }
}
