using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace QC.CorpTest.Libraries.QsprSchemaLibrary;

public class source
{
	[XmlIgnore]
	internal static int dataSetId = 1;

	[XmlIgnore]
	private bool isTestConfigurationTestAdded;

	[XmlIgnore]
	private string testerConfigDataSetReference = string.Empty;

	private ArrayList testColl;

	private TestColl validTestCollection;

	[XmlElement(Type = typeof(TestColl))]
	public ArrayList TestCollection
	{
		get
		{
			return testColl;
		}
		set
		{
			testColl = value;
		}
	}

	[XmlIgnore]
	public TestColl ValidTestCollection
	{
		get
		{
			return validTestCollection;
		}
		set
		{
			validTestCollection = value;
		}
	}

	internal void CreateTestCollection()
	{
		if (validTestCollection == null)
		{
			TestCollection = new ArrayList();
			TestColl value = new TestColl();
			TestCollection.Add(value);
			validTestCollection = value;
			dataSetId = 1;
		}
	}

	public void AddConfiguration(string serialNumber, string testerID, string dvtFlag, DateTime startDateTime, DateTime stopDateTime, string globalResult, string workStation, string comments = "", string machineName = "")
	{
		AddConfiguration(serialNumber, testerID, dvtFlag, startDateTime, stopDateTime, globalResult, null, null, null, null, workStation, comments, machineName);
	}

	public void AddConfiguration(string serialNumber, string testerID, string dvtFlag, DateTime startDateTime, DateTime stopDateTime, string globalResult, string treeFileName, string uncFileName, string swBuildId, Dictionary<string, string> swDllsDict, string workStation, string comments = "", string machineName = "")
	{
		CreateTestCollection();
		validTestCollection.AddConfiguration(serialNumber, testerID, dvtFlag, startDateTime, stopDateTime, globalResult, treeFileName, uncFileName, swBuildId, swDllsDict, workStation, comments, machineName);
	}

	public void AddConfigurationTest(Dictionary<string, string> configInformationDict)
	{
		CreateTestCollection();
		validTestCollection.AddTest("$TesterConfiguration$", "passed");
		validTestCollection.AddLoopConditionsToCurrentTest(configInformationDict);
		testerConfigDataSetReference = validTestCollection.GetDataSetId(configInformationDict);
		isTestConfigurationTestAdded = true;
	}

	public void AddTest(string testName, string testResult)
	{
		AddTest(testName, testName, testName, testResult, DateTime.MinValue, DateTime.MinValue, TimeSpan.MinValue);
	}

	public void AddTest(string testName, string nodeName, string extendedName, string testResult, DateTime testStartTime, DateTime testStopTime, TimeSpan testDuration, bool useRealNameAsDefault = false)
	{
		CreateTestCollection();
		validTestCollection.AddTest(testName, nodeName, extendedName, testResult, testStartTime, testStopTime, testDuration, useRealNameAsDefault);
		if (isTestConfigurationTestAdded)
		{
			validTestCollection.AddDataSetRefIdToCurrentTest(testerConfigDataSetReference);
		}
	}

	public void AddLoopConditionsToCurrentTest(Dictionary<string, string> loopValueDictionary)
	{
		CreateTestCollection();
		if (validTestCollection.currentTest != null)
		{
			validTestCollection.AddLoopConditionsToCurrentTest(loopValueDictionary);
		}
	}

	public void AddParameterToCurrentTest(string parameterName, string numericalValue, string charValue, string upperLimit, string lowerLimit, string unitOfMeasure)
	{
		if (!string.IsNullOrWhiteSpace(parameterName))
		{
			CreateTestCollection();
			if (validTestCollection.currentTest != null)
			{
				validTestCollection.AddParameterToCurrentTest(parameterName, numericalValue, charValue, upperLimit, lowerLimit, unitOfMeasure);
			}
		}
	}

	public void StartNewDataSetInCurrentTest()
	{
		CreateTestCollection();
		if (validTestCollection.currentTest != null)
		{
			validTestCollection.StartNewDataSetInCurrentTest();
			if (isTestConfigurationTestAdded)
			{
				validTestCollection.AddDataSetRefIdToCurrentTest(testerConfigDataSetReference);
			}
		}
	}
}
