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

namespace QC.CorpTest.Libraries.QsprSchemaLibrary;

[Serializable]
public class TestColl
{
	public struct DateInfo
	{
		public int MM;

		public int DD;

		public int YYYY;
	}

	public class TesterInfo
	{
		public class SWConfigInformation
		{
			private VersionInformation versionInfo;

			public VersionInformation Versions
			{
				get
				{
					return versionInfo;
				}
				set
				{
					versionInfo = value;
				}
			}
		}

		public class VersionInformation
		{
			private ArrayList diValues;

			[XmlElement(Type = typeof(DIValue))]
			public ArrayList DI
			{
				get
				{
					return diValues;
				}
				set
				{
					diValues = value;
				}
			}
		}

		public string Name;

		public string Type;

		private string _comments;

		private string _machineNameFromXml;

		private SWConfigInformation swConfig;

		private ArrayList equipmentConfigColl;

		public string Comments
		{
			get
			{
				return _comments;
			}
			set
			{
				_comments = value;
			}
		}

		public string MachineName
		{
			get
			{
				return _machineNameFromXml;
			}
			set
			{
				_machineNameFromXml = value;
			}
		}

		public SWConfigInformation SWConfigInfo
		{
			get
			{
				return swConfig;
			}
			set
			{
				swConfig = value;
			}
		}

		[XmlElement(Type = typeof(DIValue))]
		public ArrayList EquipmentConfig
		{
			get
			{
				return equipmentConfigColl;
			}
			set
			{
				equipmentConfigColl = value;
			}
		}
	}

	public struct ImageInfo
	{
		public DIValue DI;

		public string Filename;

		public string UNCFilename;
	}

	public class UUTInfo
	{
		public string ID;

		public string SWBuildID;

		public string Type;

		public string BasebandID;
	}

	public struct PassFailInfo
	{
		public DIValue DI;
	}

	private TimeInfo timeInfo;

	private DateInfo date;

	private DateInfo stopDate;

	private TesterInfo tester;

	private ImageInfo image;

	private UUTInfo uut;

	private PassFailInfo passfail;

	private ArrayList testColl;

	private Dictionary<string, string> hashLoopRefID = new Dictionary<string, string>();

	[XmlIgnore]
	internal Tests currentTest;

	public TimeInfo Time
	{
		get
		{
			return timeInfo;
		}
		set
		{
			timeInfo = value;
		}
	}

	public DateInfo Date
	{
		get
		{
			return date;
		}
		set
		{
			date = value;
		}
	}

	public DateInfo StopDate
	{
		get
		{
			return stopDate;
		}
		set
		{
			stopDate = value;
		}
	}

	public TesterInfo Tester
	{
		get
		{
			return tester;
		}
		set
		{
			tester = value;
		}
	}

	public ImageInfo Image
	{
		get
		{
			return image;
		}
		set
		{
			image = value;
		}
	}

	public UUTInfo UUT
	{
		get
		{
			return uut;
		}
		set
		{
			uut = value;
		}
	}

	public PassFailInfo PassFail
	{
		get
		{
			return passfail;
		}
		set
		{
			passfail = value;
		}
	}

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

	public string GetTesterId()
	{
		if (Tester != null)
		{
			return Tester.Type;
		}
		return null;
	}

	internal 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 machineNameFromXml = "")
	{
		UUT = new UUTInfo();
		UUT.ID = serialNumber;
		if (!string.IsNullOrEmpty(swBuildId))
		{
			UUT.SWBuildID = swBuildId;
		}
		TesterInfo testerInfo = new TesterInfo();
		testerInfo.Name = workStation;
		testerInfo.Type = testerID;
		testerInfo.Comments = comments;
		testerInfo.MachineName = machineNameFromXml;
		if (swDllsDict != null && swDllsDict.Count > 0)
		{
			testerInfo.SWConfigInfo = new TesterInfo.SWConfigInformation();
			testerInfo.SWConfigInfo.Versions = new TesterInfo.VersionInformation();
			testerInfo.SWConfigInfo.Versions.DI = new ArrayList();
			foreach (KeyValuePair<string, string> item in swDllsDict)
			{
				DIValue dIValue = new DIValue();
				dIValue.N = item.Key;
				dIValue.V = item.Value;
				testerInfo.SWConfigInfo.Versions.DI.Add(dIValue);
			}
		}
		Tester = testerInfo;
		Time = new TimeInfo();
		TimeInfo.info start = default(TimeInfo.info);
		start.HH = startDateTime.Hour;
		start.MM = startDateTime.Minute;
		start.SS = startDateTime.Second;
		Time.Start = start;
		TimeInfo.info stop = default(TimeInfo.info);
		stop.HH = stopDateTime.Hour;
		stop.MM = stopDateTime.Minute;
		stop.SS = stopDateTime.Second;
		Time.Stop = stop;
		TimeSpan timeSpan = stopDateTime.Subtract(startDateTime);
		TimeInfo.durationinfo duration = default(TimeInfo.durationinfo);
		duration.HH = timeSpan.Hours;
		duration.MM = timeSpan.Minutes;
		duration.SS = timeSpan.Seconds;
		duration.MS = timeSpan.Milliseconds;
		Time.Duration = duration;
		PassFailInfo passFail = default(PassFailInfo);
		passFail.DI = new DIValue();
		passFail.DI.N = "Status";
		if (globalResult.ToLower() == "failed")
		{
			passFail.DI.V = "FAIL";
		}
		else if (globalResult.ToLower() == "passed")
		{
			passFail.DI.V = "PASS";
		}
		else
		{
			passFail.DI.V = "Unknown";
		}
		PassFail = passFail;
		DateInfo dateInfo = default(DateInfo);
		dateInfo.DD = startDateTime.Day;
		dateInfo.MM = startDateTime.Month;
		dateInfo.YYYY = startDateTime.Year;
		Date = dateInfo;
		DateInfo dateInfo2 = default(DateInfo);
		dateInfo2.DD = stopDateTime.Day;
		dateInfo2.MM = stopDateTime.Month;
		dateInfo2.YYYY = stopDateTime.Year;
		StopDate = dateInfo2;
		if (!string.IsNullOrEmpty(treeFileName))
		{
			ImageInfo imageInfo = default(ImageInfo);
			imageInfo.Filename = treeFileName;
			if (!string.IsNullOrEmpty(uncFileName))
			{
				imageInfo.UNCFilename = uncFileName;
			}
			else
			{
				imageInfo.UNCFilename = treeFileName;
			}
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(treeFileName);
			imageInfo.DI = new DIValue();
			imageInfo.DI.N = fileNameWithoutExtension;
			Image = imageInfo;
		}
	}

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

	internal void AddTest(string testName, string nodeName, string extendedName, string testResult, DateTime testStartTime, DateTime testStopTime, TimeSpan testDuration, bool useRealNameAsDefault = false)
	{
		Tests tests = new Tests();
		tests.InitializeDataSetCollection();
		if (useRealNameAsDefault && !string.IsNullOrEmpty(nodeName))
		{
			tests.ExtendedName = nodeName;
			tests.Name = nodeName;
			tests.NodeName = nodeName;
		}
		else
		{
			tests.ExtendedName = extendedName;
			tests.NodeName = nodeName;
			tests.Name = testName;
		}
		tests.PassFail = new Input();
		tests.PassFail.DI = new ArrayList();
		DIValue dIValue = new DIValue();
		tests.PassFail.DI.Add(dIValue);
		dIValue.N = "Status";
		if (testResult.ToLower() == "failed")
		{
			dIValue.V = "FAIL";
		}
		else if (testResult.ToLower() == "passed")
		{
			dIValue.V = "PASS";
		}
		else
		{
			dIValue.V = "Unknown";
		}
		if (Test == null)
		{
			Test = new ArrayList();
		}
		if (DateTime.MinValue != testStartTime && DateTime.MinValue != testStopTime && TimeSpan.MinValue != testDuration)
		{
			tests.Time = new TimeInfo();
			TimeInfo.info start = default(TimeInfo.info);
			start.HH = testStartTime.Hour;
			start.MM = testStartTime.Minute;
			start.SS = testStartTime.Second;
			tests.Time.Start = start;
			TimeInfo.info stop = default(TimeInfo.info);
			stop.HH = testStopTime.Hour;
			stop.MM = testStopTime.Minute;
			stop.SS = testStopTime.Second;
			tests.Time.Stop = stop;
			TimeInfo.durationinfo duration = default(TimeInfo.durationinfo);
			duration.HH = testDuration.Hours;
			duration.MM = testDuration.Minutes;
			duration.SS = testDuration.Seconds;
			duration.MS = testDuration.Milliseconds;
			tests.Time.Duration = duration;
		}
		Test.Add(tests);
		currentTest = tests;
	}

	internal void AddLoopConditionsToCurrentTest(Dictionary<string, string> loopValueDictionary)
	{
		if (currentTest == null)
		{
			return;
		}
		int num = -1;
		string text = string.Empty;
		int num2 = 0;
		string referencedDataSetId = string.Empty;
		foreach (KeyValuePair<string, string> item in loopValueDictionary)
		{
			text = text + " " + item.Key + "__" + item.Value;
			if (hashLoopRefID.ContainsKey(text))
			{
				referencedDataSetId = hashLoopRefID[text];
				num = num2;
			}
			num2++;
		}
		num2 = 0;
		foreach (KeyValuePair<string, string> item2 in loopValueDictionary)
		{
			if (num2 > num)
			{
				currentTest.AddLoopCondition(item2.Key, item2.Value);
			}
			num2++;
		}
		if (num >= 0)
		{
			currentTest.AddNewDataSetReference(referencedDataSetId);
		}
		if (!hashLoopRefID.ContainsKey(text))
		{
			hashLoopRefID.Add(text, currentTest.currentDataSet.id);
		}
	}

	internal void AddParameterToCurrentTest(string parameterName, string numericalValue, string charValue, string upperLimit, string lowerLimit, string unitOfMeasure)
	{
		if (currentTest != null)
		{
			currentTest.AddParameter(parameterName, numericalValue, charValue, upperLimit, lowerLimit, unitOfMeasure);
		}
	}

	internal void StartNewDataSetInCurrentTest()
	{
		if (currentTest != null)
		{
			currentTest.StartNewDataSet();
		}
	}

	internal string GetDataSetId(Dictionary<string, string> loopValueDictionary)
	{
		string text = string.Empty;
		string result = string.Empty;
		foreach (KeyValuePair<string, string> item in loopValueDictionary)
		{
			text = text + " " + item.Key + "__" + item.Value;
			if (hashLoopRefID.ContainsKey(text))
			{
				result = hashLoopRefID[text];
			}
		}
		return result;
	}

	internal void AddDataSetRefIdToCurrentTest(string id)
	{
		if (currentTest != null)
		{
			currentTest.AddNewDataSetReference(id);
		}
	}
}
