using UnityEngine;
using System.Collections;

public class LevelDifficultyHandler : MonoBehaviour {

	public int winStreakCounter = 0, loseStreakCounter = 0;
	public int maxStreak, minStreak;

	#region Message Event Listener
	void OnEnable()
	{
		EventManager.StartListening(Constants.CombinationSuccessful, delegate { UpdateStreak(true); } );
		EventManager.StartListening(Constants.CombinationFailed, delegate {	UpdateStreak(false); });
	}

	void OnDisable()
	{
		EventManager.StopListening(Constants.CombinationSuccessful, delegate { UpdateStreak(true); } );
		EventManager.StopListening(Constants.CombinationFailed, delegate {	UpdateStreak(false); });	
	}
	#endregion

	void UpdateStreak(bool isWin)
	{
		if(isWin){
			if(winStreakCounter < maxStreak)
			{
				winStreakCounter++;
			}
			else
			{
				IncreaseDifficulty();
			}
		}
		else{
			DecreaseDifficulty();
		}
	}

	void IncreaseDifficulty()
	{
		winStreakCounter = 0;
		EventManager.TriggerEvent(Constants.IncreaseDifficulty);
	}

	void DecreaseDifficulty()
	{
		winStreakCounter = 0;
		EventManager.TriggerEvent(Constants.DecreaseDifficulty);
	}
}
