using System.Collections.Generic;
using QC.MCI;

namespace QC.MultiplexManager;

public class EnvManager
{
	private static EnvManager m_instance = new EnvManager();

	private Dictionary<string, string> m_globalVariables;

	public static EnvManager GetInstance()
	{
		return m_instance;
	}

	public string GetGlobalVariable(string name)
	{
		string value = "";
		if (QTMDotNetInterfaceManager.GetInstance().isValid())
		{
			return QTMDotNetInterfaceManager.GetInstance().GetGlobalVariable(name);
		}
		bool flag = false;
		if (m_globalVariables.TryGetValue(name, out value))
		{
			return value;
		}
		return MCI_EnvManager.GetInstance().GetGlobalVariable(name);
	}

	public void SetGlobalVariable(string name, string value)
	{
		if (QTMDotNetInterfaceManager.GetInstance().isValid())
		{
			QTMDotNetInterfaceManager.GetInstance().SetGlobalVariable(name, value);
			return;
		}
		if (!m_globalVariables.ContainsKey(name))
		{
			m_globalVariables.Add(name, value);
		}
		else
		{
			m_globalVariables[name] = value;
		}
		MCI_EnvManager.GetInstance().SetGlobalVariable(name, value);
	}

	public void DebugMessageWrite(string name, string text)
	{
		if (QTMDotNetInterfaceManager.GetInstance().isValid())
		{
			QTMDotNetInterfaceManager.GetInstance().DebugMessageWrite(name, text);
		}
	}

	public void DebugMessageTPLStartContext(string name, string testName, string text)
	{
		if (QTMDotNetInterfaceManager.GetInstance().isValid())
		{
			QTMDotNetInterfaceManager.GetInstance().DebugMessageTPLStartContext(name, testName, text);
		}
	}

	public void DebugMessageTPLStopContext(string name)
	{
		if (QTMDotNetInterfaceManager.GetInstance().isValid())
		{
			QTMDotNetInterfaceManager.GetInstance().DebugMessageTPLStopContext(name);
		}
	}

	public string QTMInfoGetTestName()
	{
		if (QTMDotNetInterfaceManager.GetInstance().isValid())
		{
			return QTMDotNetInterfaceManager.GetInstance().QTMInfoCurrentTestName();
		}
		return "Test";
	}

	private EnvManager()
	{
		m_globalVariables = new Dictionary<string, string>();
	}
}
