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

namespace QC.CorpTest.Libraries.QsprSchemaLibrary;

[Serializable]
public class Tests
{
	private string name;

	private string extendedName;

	private string nodeName;

	private TimeInfo timeInfo;

	private ArrayList myDataSet;

	private Input passFail;

	private Input errorCode;

	[XmlIgnore]
	internal DataSetColl currentDataSetCollection;

	[XmlIgnore]
	internal DataSets currentDataSet;

	public string Name
	{
		get
		{
			return name;
		}
		set
		{
			name = value;
		}
	}

	public string ExtendedName
	{
		get
		{
			return extendedName;
		}
		set
		{
			extendedName = value;
		}
	}

	public string NodeName
	{
		get
		{
			return nodeName;
		}
		set
		{
			nodeName = value;
		}
	}

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

	[XmlElement(Type = typeof(DataSetColl))]
	public ArrayList DataSetCollection
	{
		get
		{
			return myDataSet;
		}
		set
		{
			myDataSet = value;
		}
	}

	public Input PassFail
	{
		get
		{
			return passFail;
		}
		set
		{
			passFail = value;
		}
	}

	public Input ErrorCode
	{
		get
		{
			return errorCode;
		}
		set
		{
			errorCode = value;
		}
	}

	internal void AddParameter(string parameterName, string numericalValue, string charValue, string upperLimit, string lowerLimit, string unitOfMeasure)
	{
		Results results = new Results();
		results.DI = new DIValue();
		results.DI.N = parameterName;
		if (string.IsNullOrEmpty(numericalValue))
		{
			results.DI.V = charValue;
		}
		else
		{
			results.DI.V = numericalValue;
			Results.Limit limit = new Results.Limit();
			limit.Max = upperLimit;
			limit.Min = lowerLimit;
			results.Limits = limit;
			string text = "";
			if (double.TryParse(numericalValue, out var result))
			{
				text = "PASS";
				if (double.TryParse(lowerLimit, out var result2) && double.TryParse(upperLimit, out var result3))
				{
					text = ((!(result >= result2) || !(result <= result3)) ? "FAIL" : "PASS");
				}
				else if (double.TryParse(lowerLimit, out result2))
				{
					text = ((!(result >= result2)) ? "FAIL" : "PASS");
				}
				else if (double.TryParse(upperLimit, out result3))
				{
					text = ((!(result <= result3)) ? "FAIL" : "PASS");
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				results.Limits.PassFail = new Results.Limit.PassFailLimInfo();
				results.Limits.PassFail.DI = new DIValue();
				results.Limits.PassFail.DI.N = "Status";
				results.Limits.PassFail.DI.V = text;
			}
			results.DI.U = unitOfMeasure;
		}
		if (currentDataSet.Outputs == null)
		{
			currentDataSet.Outputs = new Output();
		}
		if (currentDataSet.Outputs.Result == null)
		{
			currentDataSet.Outputs.Result = new ArrayList();
		}
		currentDataSet.Outputs.Result.Add(results);
	}

	internal void InitializeDataSetCollection()
	{
		if (DataSetCollection == null)
		{
			DataSetCollection = new ArrayList();
			DataSetColl value = new DataSetColl();
			DataSetCollection.Add(value);
			currentDataSetCollection = value;
			currentDataSetCollection.DataSet = new ArrayList();
			DataSets dataSets = new DataSets();
			dataSets.id = source.dataSetId.ToString();
			source.dataSetId++;
			currentDataSetCollection.DataSet.Add(dataSets);
			currentDataSet = dataSets;
		}
	}

	internal void AddLoopCondition(string loopName, string loopValue)
	{
		DIValue dIValue = new DIValue();
		dIValue.N = loopName;
		dIValue.V = loopValue;
		if (currentDataSet.Inputs == null)
		{
			currentDataSet.Inputs = new Input();
		}
		if (currentDataSet.Inputs.DI == null)
		{
			currentDataSet.Inputs.DI = new ArrayList();
		}
		currentDataSet.Inputs.DI.Add(dIValue);
	}

	internal void AddNewDataSetReference(string referencedDataSetId)
	{
		DSRefInfo dSRefInfo = new DSRefInfo();
		dSRefInfo.id = referencedDataSetId;
		if (currentDataSet.DSRef == null)
		{
			currentDataSet.DSRef = new ArrayList();
		}
		currentDataSet.DSRef.Add(dSRefInfo);
	}

	internal void StartNewDataSet()
	{
		DataSets dataSets = new DataSets();
		dataSets.id = source.dataSetId.ToString();
		source.dataSetId++;
		currentDataSetCollection.DataSet.Add(dataSets);
		currentDataSet = dataSets;
	}
}
