using UnityEngine;
using System.Collections;

public enum FPSQuality
{
    Low,
    High,
    Max
}

[System.Serializable]
public class ConfigData : StorageData
{
	public FPSQuality m_fps = FPSQuality.Max;
    public bool m_vsynch = true;

    public int m_musicVolume = 100;
    public int m_ambientVolume = 100;
    public int m_sfxVolume = 100;

    public bool m_showFps = false;

    public ConfigData()
    {
    }
}

public class Config : MonoBehaviourSingleton<Config>
{
    public string BuildName = "";

    public ConfigData m_data;

    public const float ScreenWidth = 1920;
	public const float ScreenHeight = 1080;
	
	public const string HomeWWW = "www.LastTales.com";
	public const string HomeURL = "http://" + HomeWWW;
    public const string SteamURL = "https://store.steampowered.com/app/867980/Raiders_Of_The_Lost_Island";

#if UNITY_ANDROID
		public const string AppURL = "market://details?id=YOUR_ID";
#elif UNITY_IPHONE
		public const string AppURL = "itms-apps://itunes.apple.com/app/id1175839537";
#else
    public const string AppURL = HomeURL;
#endif

	Config()
	{
		m_data = new ConfigData();
	}

	public void OnInit()
	{
		LoadConfig();
	}

	private void LoadConfig()
	{
		Storage.Load<ConfigData>(ref m_data, "config.cfg");
    }

	public void SaveConfig()
	{
		Storage.Save<ConfigData>(ref m_data, "config.cfg");
	}

    /*
    private void LateUpdate()
    {
        DebugMenu.Add(OnDebugMenu);
    }
    */

/*
    void OnDebugMenu()
    {
        if (DebugMenu.Group("SYSTEM"))
        {
            DebugMenu.Label("Demo v" + Application.version + " " + BuildName);
            DebugMenu.Label("FPS " + FPS.m_fps);
            DebugMenu.Label("Quality " + QualitySettings.GetQualityLevel());
            DebugMenu.Label("Resolution " + Screen.width + " x " + Screen.height);
            DebugMenu.Label(SystemInfo.operatingSystem);
            DebugMenu.Label(SystemInfo.processorType);
            DebugMenu.Label(SystemInfo.graphicsDeviceName);
            DebugMenu.Label(SystemInfo.graphicsDeviceVersion);
            DebugMenu.Label("VRAM " + SystemInfo.graphicsMemorySize);
            DebugMenu.Label("SHD " + SystemInfo.graphicsShaderLevel);
            
            //@TODO: show controllers as well?
        }

        if (DebugMenu.Group("CONFIG"))
        {
            if (DebugMenu.Button("VSynch: " + (m_data.m_vsynch ? "ON" : "OFF")))
            {
                m_data.m_vsynch = !m_data.m_vsynch;
                App.instance.ApplyFpsQuality();
            }

            if (DebugMenu.Button("FPS: " + (m_data.m_fps == FPSQuality.Max ? "Max" : (m_data.m_fps == FPSQuality.High ? "High" : "Low"))))
            {
                m_data.m_fps = (m_data.m_fps == FPSQuality.Max) ? FPSQuality.Low : (m_data.m_fps == FPSQuality.High ? FPSQuality.Max : FPSQuality.High);
                App.instance.ApplyFpsQuality();
            }

            if (DebugMenu.Button("Show FPS: " + (m_data.m_showFps ? "ON" : "OFF")))
            {
                m_data.m_showFps = !m_data.m_showFps;
                FPS.Show(m_data.m_showFps);
            }

            if (DebugMenu.Button("SAVE CONFIG"))
                SaveConfig();

            // Eg:
            // DebugMenu.Label("t = " + t);
            // t = DebugMenu.Slider(t, 0, 5, 1);
        }

    }
*/
}
