namespace QC.QTMInterface;

public class TestTreeFns
{
	public static bool SelectTest(TTDPlugIn thisPlugin, string TestName)
	{
		try
		{
			TTDPluginEventArgs tTDPluginEventArgs = new TTDPluginEventArgs();
			tTDPluginEventArgs.Key = "Select Test Node";
			SelectNodeInfo selectNodeInfo = default(SelectNodeInfo);
			selectNodeInfo.IsRealName = true;
			selectNodeInfo.TestName = TestName.Trim();
			selectNodeInfo.IsPartialName = true;
			tTDPluginEventArgs.Message = selectNodeInfo;
			tTDPluginEventArgs.MessageCategory = CallbackCategory.SPECIAL_MESSAGE;
			return thisPlugin.OnTTDPluginHandler(thisPlugin, tTDPluginEventArgs).Result;
		}
		catch
		{
			return false;
		}
	}

	public static bool RunSelectedTest(TTDPlugIn thisPlugin, object paramList)
	{
		try
		{
			TTDPluginEventArgs tTDPluginEventArgs = new TTDPluginEventArgs();
			tTDPluginEventArgs.Key = "Run Selected Test";
			tTDPluginEventArgs.Message = paramList;
			tTDPluginEventArgs.MessageCategory = CallbackCategory.SPECIAL_MESSAGE;
			return thisPlugin.OnTTDPluginHandler(thisPlugin, tTDPluginEventArgs).Result;
		}
		catch
		{
			return false;
		}
	}

	public static bool GetSelectedTestParam(TTDPlugIn thisPlugin, out object paramList)
	{
		paramList = null;
		try
		{
			paramList = null;
			TTDPluginEventArgs tTDPluginEventArgs = new TTDPluginEventArgs();
			tTDPluginEventArgs.Key = "Get Selected Test Parameters";
			tTDPluginEventArgs.MessageCategory = CallbackCategory.SPECIAL_MESSAGE;
			CallbackResultInfo callbackResultInfo = thisPlugin.OnTTDPluginHandler(thisPlugin, tTDPluginEventArgs);
			if (callbackResultInfo.Result)
			{
				paramList = callbackResultInfo.Message;
			}
			return callbackResultInfo.Result;
		}
		catch
		{
			paramList = null;
			return false;
		}
	}

	public static TestResult GetSelectedTestResult(TTDPlugIn thisPlugin)
	{
		TestResult result = TestResult.Failed;
		try
		{
			TTDPluginEventArgs tTDPluginEventArgs = new TTDPluginEventArgs();
			tTDPluginEventArgs.Key = "Get Selected Test Result";
			tTDPluginEventArgs.MessageCategory = CallbackCategory.SPECIAL_MESSAGE;
			CallbackResultInfo callbackResultInfo = thisPlugin.OnTTDPluginHandler(thisPlugin, tTDPluginEventArgs);
			if (callbackResultInfo.Result)
			{
				result = (TestResult)callbackResultInfo.Message;
			}
		}
		catch
		{
		}
		return result;
	}
}
