using System;
using System.Collections.Generic;
using System.Diagnostics;
using QC.QTMInterface;

namespace QC.QTMDotNetKernelInterface.Environment;

public class DebugMessage
{
	private QSPREnvironment env;

	public event DotNetTextOutEventHandler OnTextOut;

	public event DotNetPrintDebugEventHandler OnPrintDebug;

	public event DotNetClearEventHandler OnClearDebugMsg;

	public event DotNetSaveEventHandler OnSaveDebugMsg;

	public event DotNetClearAllEventHandler OnClearAllDebugMsg;

	public event DotNetSaveAllEventHandler OnSaveAllDebugMsg;

	public event DotNetTpl2WindowEventHandler OnTpl2WindowMsg;

	public event DotNetHTMLWindowEventHandler OnHTMLWindowMsg;

	public event DotNetGenericMessageEventHandler OnGenericMsg;

	public event DotNetGenericParamMessageEventHandler OnGenericParamMsg;

	public event DotNetCustomMessageEventHandler OnCustomMsg;

	public event SetDebugWindowInFocusEventHandler OnSetDebugWindowInFocus;

	internal DebugMessage(QSPREnvironment env)
	{
		this.env = env;
	}

	public void Write(string debugWindowName, string debugText)
	{
		Write(debugWindowName, debugText, TraceLevel.Verbose);
	}

	public void Write(string debugWindowName, string debugText, TraceLevel traceLevel)
	{
		if (this.OnTextOut != null)
		{
			this.OnTextOut(debugWindowName, debugText, traceLevel);
		}
	}

	public void Clear(string debugWindowName)
	{
		if (this.OnClearDebugMsg != null)
		{
			this.OnClearDebugMsg(debugWindowName);
		}
	}

	public void ClearAll()
	{
		if (this.OnClearAllDebugMsg != null)
		{
			this.OnClearAllDebugMsg();
		}
	}

	public void EndLogging()
	{
		SendGenericMessage("OnEndLog", null, 7);
	}

	public void StartLogging()
	{
		SendGenericMessage("OnStartLog", null, 7);
	}

	public void ClearGlobalTreeResult()
	{
		SendGenericMessage("ClearGlobalTreeResult", null, 7);
	}

	public void Save(string debugWindowName, bool appendText)
	{
		if (this.OnSaveDebugMsg != null)
		{
			this.OnSaveDebugMsg(debugWindowName, appendText);
		}
	}

	public void SaveAll(bool appendText)
	{
		if (this.OnSaveAllDebugMsg != null)
		{
			this.OnSaveAllDebugMsg(appendText);
		}
	}

	public void PrintMessage(string debugWindowName, bool IsHeader, params string[] Values)
	{
		if (this.OnPrintDebug != null)
		{
			if (IsHeader)
			{
				this.OnPrintDebug(debugWindowName, PrintMsgOptions.HeaderInfo, Values);
			}
			else
			{
				this.OnPrintDebug(debugWindowName, PrintMsgOptions.RowInfo, Values);
			}
		}
	}

	public void SetFilterForPrintMessage(string debugWindowName, string ColumnHeaderName)
	{
		if (this.OnPrintDebug != null)
		{
			this.OnPrintDebug(debugWindowName, PrintMsgOptions.FilterColInfo, ColumnHeaderName);
		}
	}

	public void TPLSetFilters(string debugWindowName, List<string> filterList)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			Tpl2Info commandInfo = default(Tpl2Info);
			commandInfo.FilterList = filterList;
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.SetFilters, commandInfo);
		}
	}

	public void TPLPrintMessage(string debugWindowName, string filter, string message)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			Tpl2Info commandInfo = default(Tpl2Info);
			commandInfo.FilterValue = filter;
			commandInfo.Message = message;
			commandInfo.SystemTime = DateTime.Now;
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.PrintMessage, commandInfo);
		}
	}

	public void TPLSaveToFile(string debugWindowName, string fileName)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			Tpl2Info commandInfo = default(Tpl2Info);
			commandInfo.SaveFileName = fileName;
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.SaveToTPL2, commandInfo);
		}
	}

	public void TPLStartTest(string debugWindowName, string testName)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			Tpl2Info commandInfo = default(Tpl2Info);
			commandInfo.TestName = testName;
			commandInfo.SystemTime = DateTime.Now;
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.StartTest, commandInfo);
		}
	}

	public void TPLStartContext(string debugWindowName, string contextName, string contextType)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			Tpl2Info commandInfo = default(Tpl2Info);
			commandInfo.ContextName = contextName;
			commandInfo.ContextType = contextType;
			commandInfo.SystemTime = DateTime.Now;
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.StartContext, commandInfo);
		}
	}

	public void TPLStopContext(string debugWindowName)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			Tpl2Info commandInfo = default(Tpl2Info);
			commandInfo.SystemTime = DateTime.Now;
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.StopContext, commandInfo);
		}
	}

	public void TPLStopTest(string debugWindowName)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			Tpl2Info commandInfo = default(Tpl2Info);
			commandInfo.SystemTime = DateTime.Now;
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.StopTest, commandInfo);
		}
	}

	public void TPLClear(string debugWindowName)
	{
		if (this.OnTpl2WindowMsg != null)
		{
			this.OnTpl2WindowMsg(debugWindowName, Tpl2Command.Clear, default(Tpl2Info));
		}
	}

	public void HTMLWindowNavigate(string URL)
	{
		if (this.OnHTMLWindowMsg != null)
		{
			this.OnHTMLWindowMsg("HTML", HTMLCommand.HTML_NAVIGATE, URL);
		}
	}

	public void SendGenericMessage(string messageType, GenericTestData data = null, byte pluginTypes = 7, string pluginNames = "")
	{
		if (this.OnGenericMsg != null)
		{
			this.OnGenericMsg(messageType, data, pluginTypes, pluginNames);
		}
	}

	public void SendGenericParamMessage(string messageType, string id = "", string name = "", string value = "", string units = "", string lowerLimit = "", string upperLimit = "", byte pluginTypes = 7, string pluginNames = "")
	{
		if (this.OnGenericParamMsg != null)
		{
			this.OnGenericParamMsg(messageType, id, name, value, units, lowerLimit, upperLimit, pluginTypes, pluginNames);
		}
	}

	public void SendCustomMessage(object messageData, byte pluginTypes = 7, string pluginNames = "")
	{
		if (this.OnCustomMsg != null)
		{
			this.OnCustomMsg(messageData, pluginTypes, pluginNames);
		}
	}

	public void SetDebugWindowInFocus(string debugWindowName)
	{
		if (this.OnSetDebugWindowInFocus != null)
		{
			this.OnSetDebugWindowInFocus(debugWindowName);
		}
	}
}
