using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class EndSceneScript : MonoBehaviour {
    public GameObject GameOverText;
    public GameObject SuccessText;
    public GameObject SubMessage;
    public AudioClip BadEnding;
    public AudioClip GoodEnding;
    private AudioSource audioSource;

	void Start () {
        audioSource = GetComponent<AudioSource>();
	   if(ApplicationModel.success == true)
       {
           Invoke("GoToStart", 10f);
           SuccessText.SetActive(true);
           audioSource.PlayOneShot(GoodEnding);
       }
       else
       {
           GameOverText.SetActive(true);
           Invoke("GoToStart", 6f);
           audioSource.PlayOneShot(BadEnding);
       }
       if(ApplicationModel.successRate == 1.0f)
       {
            SetSubMessage("Shaman Hacker. Perfect ritual.");
       }
       else if(ApplicationModel.successRate >= 0.9f)
       {
            SetSubMessage("Ultra awesome ritual.");
       }
       else if(ApplicationModel.successRate >= ApplicationModel.maxFailRate)
       {
            SetSubMessage("Very good, but not perfect!");
       }
       else if(ApplicationModel.successRate >= (ApplicationModel.maxFailRate * 0.8f))
       {
            SetSubMessage("Better luck next time, Shaman!");
       }
       else
       {
            SetSubMessage("Not even close... Do you even try?");
       }

    }
    private void GoToStart()
    {
        SceneManager.LoadScene("main_menu");
    }

    public void SetSubMessage(string msg)
    {
        foreach(var text in SubMessage.GetComponentsInChildren<Text>())
        {
            text.text = msg;
        }
    }
}
