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

namespace QC.QSPRLogSchema;

[Serializable]
[XmlType(AnonymousType = true)]
public class Test
{
	[XmlIgnore]
	private static object nextTestIndexLock = new object();

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private List<DataItem> testConfigField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private TestCase testCaseField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private TestStatus statusField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private DataSet dsField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string nField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string nodeNameField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string fullPathField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string startTimeField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string stopTimeField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string durationField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string tcCaseRefIdField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string techField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string grpIdField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private string crNumberField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private int _index;

	[XmlIgnore]
	public List<Test> ChildTests = new List<Test>();

	[XmlIgnore]
	public bool TestCaseFilesProcessed;

	[XmlElement("TestStepLogPath")]
	public string TestStepLogPath
	{
		get
		{
			if (UseLocalTestCaseFilePath)
			{
				return LocalTestCaseFile;
			}
			return RemoteTestCaseFile;
		}
		set
		{
			if (UseLocalTestCaseFilePath)
			{
				LocalTestCaseFile = value;
			}
			else
			{
				RemoteTestCaseFile = value;
			}
		}
	}

	[XmlIgnore]
	public string LocalTestCaseFile { get; set; }

	[XmlIgnore]
	public string RemoteTestCaseFile { get; set; }

	[XmlIgnore]
	public bool EnableTestStepLogPathSerialization { get; set; }

	[XmlIgnore]
	public bool UseLocalTestCaseFilePath { get; set; }

	[XmlIgnore]
	public bool LogFilesCopied => !string.IsNullOrEmpty(LogFileRemotePath);

	[XmlIgnore]
	public string LogFileRemotePath { get; set; }

	[XmlIgnore]
	public string ShortTestPath
	{
		get
		{
			if (string.IsNullOrEmpty(FullPath))
			{
				return FullPath;
			}
			char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
			string text = FullPath;
			char[] array = invalidFileNameChars;
			foreach (char oldChar in array)
			{
				try
				{
					text = text.Replace(oldChar, '_');
				}
				catch
				{
				}
			}
			if (text.Length <= 20)
			{
				return text;
			}
			return text.Substring(0, 10) + text.Substring(text.Length - 10, 10);
		}
	}

	[XmlArrayItem("DI", IsNullable = false)]
	public List<DataItem> TestConfig
	{
		get
		{
			return testConfigField;
		}
		set
		{
			testConfigField = value;
		}
	}

	public TestCase TestCase
	{
		get
		{
			return testCaseField;
		}
		set
		{
			testCaseField = value;
		}
	}

	public TestStatus Status
	{
		get
		{
			return statusField;
		}
		set
		{
			statusField = value;
		}
	}

	[XmlElement("DS")]
	public DataSet DataSet
	{
		get
		{
			return dsField;
		}
		set
		{
			dsField = value;
		}
	}

	[XmlAttribute("N")]
	public string Name
	{
		get
		{
			return nField;
		}
		set
		{
			nField = value;
		}
	}

	[XmlAttribute]
	public string NodeName
	{
		get
		{
			return nodeNameField;
		}
		set
		{
			nodeNameField = value;
		}
	}

	[XmlAttribute]
	public string FullPath
	{
		get
		{
			return fullPathField;
		}
		set
		{
			fullPathField = value;
		}
	}

	[XmlAttribute]
	public string StartTime
	{
		get
		{
			return startTimeField;
		}
		set
		{
			startTimeField = value;
		}
	}

	[XmlAttribute]
	public string StopTime
	{
		get
		{
			return stopTimeField;
		}
		set
		{
			stopTimeField = value;
		}
	}

	[XmlAttribute]
	public string Duration
	{
		get
		{
			return durationField;
		}
		set
		{
			durationField = value;
		}
	}

	[XmlAttribute]
	public string TCCaseRefId
	{
		get
		{
			return tcCaseRefIdField;
		}
		set
		{
			tcCaseRefIdField = value;
		}
	}

	[XmlAttribute("Tech")]
	public string Technology
	{
		get
		{
			return techField;
		}
		set
		{
			techField = value;
		}
	}

	[XmlAttribute("GrpId")]
	public string GroupId
	{
		get
		{
			return grpIdField;
		}
		set
		{
			grpIdField = value;
		}
	}

	[XmlAttribute]
	public string CRNumber
	{
		get
		{
			return crNumberField;
		}
		set
		{
			crNumberField = value;
		}
	}

	public int GetIndex(ref int _nextIndex)
	{
		lock (nextTestIndexLock)
		{
			if (_index == 0)
			{
				_index = ++_nextIndex;
			}
		}
		return _index;
	}

	public bool ShouldSerializeTestStepLogPath()
	{
		if (EnableTestStepLogPathSerialization)
		{
			return !string.IsNullOrEmpty(TestStepLogPath);
		}
		return false;
	}

	public bool ShouldSerializeTestConfig()
	{
		if (TestConfig != null)
		{
			return TestConfig.Count > 0;
		}
		return false;
	}

	public bool ShouldSerializeTestCase()
	{
		if (TestCase != null)
		{
			if (!TestCase.ShouldSerializeName() && !TestCase.ShouldSerializeTCCaseID() && !TestCase.ShouldSerializeTestSpecification())
			{
				return TestCase.ShouldSerializeVersion();
			}
			return true;
		}
		return false;
	}

	public bool ShouldSerializeStatus()
	{
		if (Status != null)
		{
			if (!Status.ShouldSerializeErrorCode() && !Status.ShouldSerializeComments() && !Status.ShouldSerializeLogFilePath() && !Status.ShouldSerializeStatusValue())
			{
				return Status.ShouldSerializeSkipReason();
			}
			return true;
		}
		return false;
	}

	public bool ShouldSerializeDataSet()
	{
		if (DataSet != null)
		{
			if (!DataSet.ShouldSerializeInput() && !DataSet.ShouldSerializeOutput() && !DataSet.ShouldSerializeDataSetReferences())
			{
				return DataSet.ShouldSerializeId();
			}
			return true;
		}
		return false;
	}

	public bool ShouldSerializeName()
	{
		return !string.IsNullOrEmpty(Name);
	}

	public bool ShouldSerializeNodeName()
	{
		return !string.IsNullOrEmpty(NodeName);
	}

	public bool ShouldSerializeFullPath()
	{
		return !string.IsNullOrEmpty(FullPath);
	}

	public bool ShouldSerializeStartTime()
	{
		return !string.IsNullOrEmpty(StartTime);
	}

	public bool ShouldSerializeStopTime()
	{
		return !string.IsNullOrEmpty(StopTime);
	}

	public bool ShouldSerializeDuration()
	{
		return !string.IsNullOrEmpty(Duration);
	}

	public bool ShouldSerializeTCCaseRefId()
	{
		return !string.IsNullOrEmpty(TCCaseRefId);
	}

	public bool ShouldSerializeTechnology()
	{
		return !string.IsNullOrEmpty(Technology);
	}

	public bool ShouldSerializeGroupId()
	{
		return !string.IsNullOrEmpty(GroupId);
	}

	public bool ShouldSerializeCRNumber()
	{
		return !string.IsNullOrEmpty(CRNumber);
	}

	public Test()
	{
		testConfigField = new List<DataItem>();
		testCaseField = new TestCase();
		statusField = new TestStatus();
		dsField = new DataSet();
		nField = string.Empty;
		nodeNameField = string.Empty;
		fullPathField = string.Empty;
		startTimeField = string.Empty;
		stopTimeField = string.Empty;
		durationField = string.Empty;
		tcCaseRefIdField = string.Empty;
		techField = string.Empty;
		grpIdField = string.Empty;
		crNumberField = string.Empty;
	}

	public Test(List<DataItem> testConfig = null, TestCase testCase = null, TestStatus status = null, DataSet ds = null, string n = null, string nodeName = null, string fullPath = null, string startTime = null, string stopTime = null, string duration = null, string tcCaseRefId = null, string tech = null, string grpId = null, string crNumber = null)
	{
		if (testConfig != null)
		{
			testConfigField = testConfig;
		}
		else
		{
			testConfigField = new List<DataItem>();
		}
		if (testCase != null)
		{
			testCaseField = testCase;
		}
		else
		{
			testCaseField = new TestCase();
		}
		if (status != null)
		{
			statusField = status;
		}
		else
		{
			statusField = new TestStatus();
		}
		if (ds != null)
		{
			dsField = ds;
		}
		else
		{
			dsField = new DataSet();
		}
		if (!string.IsNullOrEmpty(n))
		{
			nField = n;
		}
		else
		{
			nField = string.Empty;
		}
		if (!string.IsNullOrEmpty(nodeName))
		{
			nodeNameField = nodeName;
		}
		else
		{
			nodeNameField = string.Empty;
		}
		if (!string.IsNullOrEmpty(fullPath))
		{
			fullPathField = fullPath;
		}
		else
		{
			fullPathField = string.Empty;
		}
		if (!string.IsNullOrEmpty(startTime))
		{
			startTimeField = startTime;
		}
		else
		{
			startTimeField = string.Empty;
		}
		if (!string.IsNullOrEmpty(stopTime))
		{
			stopTimeField = stopTime;
		}
		else
		{
			stopTimeField = string.Empty;
		}
		if (!string.IsNullOrEmpty(duration))
		{
			durationField = duration;
		}
		else
		{
			durationField = string.Empty;
		}
		if (!string.IsNullOrEmpty(tcCaseRefId))
		{
			tcCaseRefIdField = tcCaseRefId;
		}
		else
		{
			tcCaseRefIdField = string.Empty;
		}
		if (!string.IsNullOrEmpty(tech))
		{
			techField = tech;
		}
		else
		{
			techField = string.Empty;
		}
		if (!string.IsNullOrEmpty(grpId))
		{
			grpIdField = grpId;
		}
		else
		{
			grpIdField = string.Empty;
		}
		if (!string.IsNullOrEmpty(crNumber))
		{
			crNumberField = crNumber;
		}
		else
		{
			crNumberField = string.Empty;
		}
	}
}
