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

namespace QC.QSPRLogSchema;

[Serializable]
[XmlType(AnonymousType = true)]
public class RunInfo
{
	[XmlIgnore]
	public int NextTestIndex;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private List<UUT> uutField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private TimeInfo dateTimeField;

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

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

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

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private Image imageField;

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private Tester testerField;

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

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

	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private TestPlan testPlanField;

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

	public TimeInfo DateTime
	{
		get
		{
			return dateTimeField;
		}
		set
		{
			dateTimeField = value;
		}
	}

	public List<UUT> UUTItems
	{
		get
		{
			return uutField;
		}
		set
		{
			uutField = value;
		}
	}

	public string OperatorID
	{
		get
		{
			return operatorIDField;
		}
		set
		{
			operatorIDField = value;
		}
	}

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

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

	public Image Image
	{
		get
		{
			return imageField;
		}
		set
		{
			imageField = value;
		}
	}

	public Tester Tester
	{
		get
		{
			return testerField;
		}
		set
		{
			testerField = value;
		}
	}

	[XmlArray("RunConfig", IsNullable = false)]
	[XmlArrayItem(typeof(DataItem), ElementName = "DI", IsNullable = false)]
	public List<DataItem> RunConfig
	{
		get
		{
			return runConfigField;
		}
		set
		{
			runConfigField = value;
		}
	}

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

	public TestPlan TestPlan
	{
		get
		{
			return testPlanField;
		}
		set
		{
			testPlanField = value;
		}
	}

	[XmlElement(IsNullable = false)]
	public string SessionDataGUID
	{
		get
		{
			return sessionDataGUIDField;
		}
		set
		{
			sessionDataGUIDField = value;
		}
	}

	public bool IncludeSkippedTestCases { get; set; }

	public bool IncludeKPI { get; set; }

	public bool IncludeTestCaseID { get; set; }

	public bool ShouldSerializeDateTime()
	{
		if (DateTime != null)
		{
			if (!DateTime.ShouldSerializeStartTime() && !DateTime.ShouldSerializeStopTime())
			{
				return DateTime.ShouldSerializeDuration();
			}
			return true;
		}
		return false;
	}

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

	public bool ShouldSerializeOperatorID()
	{
		return !string.IsNullOrEmpty(OperatorID);
	}

	public bool ShouldSerializeMachineName()
	{
		return !string.IsNullOrEmpty(MachineName);
	}

	public bool ShouldSerializeComments()
	{
		return !string.IsNullOrEmpty(Comments);
	}

	public bool ShouldSerializeImage()
	{
		if (Image != null)
		{
			if (!Image.ShouldSerializeDataItems() && !Image.ShouldSerializeFilename())
			{
				return Image.ShouldSerializeUNCFilename();
			}
			return true;
		}
		return false;
	}

	public bool ShouldSerializeTester()
	{
		if (Tester != null)
		{
			if (!Tester.ShouldSerializeSoftwareConfigurationInfoItems() && !Tester.ShouldSerializeEquipmentConfigurationDataItems() && !Tester.ShouldSerializeTesterID() && !Tester.ShouldSerializeType() && !Tester.ShouldSerializeWorkStation() && !Tester.ShouldSerializeTreeID() && !Tester.ShouldSerializeApplicationName())
			{
				return Tester.ShouldSerializeVersion();
			}
			return true;
		}
		return false;
	}

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

	public bool ShouldSerializeStatus()
	{
		if (Status != null)
		{
			if (!Status.ShouldSerializeErrorCode() && !Status.ShouldSerializeValue() && !Status.ShouldSerializeLimitName() && !Status.ShouldSerializeLimitFile())
			{
				return Status.ShouldSerializeLimitVersion();
			}
			return true;
		}
		return false;
	}

	public bool ShouldSerializeTestPlan()
	{
		if (TestPlan != null)
		{
			if (!TestPlan.ShouldSerializeId() && !TestPlan.ShouldSerializeName())
			{
				return TestPlan.ShouldSerializeVersion();
			}
			return true;
		}
		return false;
	}

	public bool ShouldSerializeSessionDataGUID()
	{
		return !string.IsNullOrEmpty(SessionDataGUID);
	}

	public RunInfo()
	{
		uutField = new List<UUT>();
		dateTimeField = new TimeInfo();
		operatorIDField = string.Empty;
		imageField = new Image();
		testerField = new Tester();
		runConfigField = new List<DataItem>();
		statusField = new Status();
		testPlanField = new TestPlan();
		machineNameField = string.Empty;
		commentsField = string.Empty;
		sessionDataGUIDField = Guid.NewGuid().ToString();
	}

	public RunInfo(List<UUT> uut = null, TimeInfo dateTime = null, string operatorID = null, Image image = null, Tester tester = null, List<DataItem> runConfig = null, Status status = null, TestPlan testPlan = null, string machineName = null, string comments = null)
	{
		if (uut != null)
		{
			uutField = uut;
		}
		else
		{
			uutField = new List<UUT>();
		}
		if (dateTime != null)
		{
			dateTimeField = dateTime;
		}
		else
		{
			dateTimeField = new TimeInfo();
		}
		if (!string.IsNullOrEmpty(operatorID))
		{
			operatorIDField = operatorID;
		}
		else
		{
			operatorIDField = string.Empty;
		}
		if (image != null)
		{
			imageField = image;
		}
		else
		{
			imageField = new Image();
		}
		if (tester != null)
		{
			testerField = tester;
		}
		else
		{
			testerField = new Tester();
		}
		if (runConfig != null)
		{
			runConfigField = runConfig;
		}
		else
		{
			runConfigField = new List<DataItem>();
		}
		if (status != null)
		{
			statusField = status;
		}
		else
		{
			statusField = new Status();
		}
		if (testPlan != null)
		{
			TestPlan = testPlan;
		}
		else
		{
			TestPlan = new TestPlan();
		}
		if (!string.IsNullOrEmpty(machineName))
		{
			machineNameField = machineName;
		}
		else
		{
			machineNameField = string.Empty;
		}
		if (!string.IsNullOrEmpty(comments))
		{
			commentsField = comments;
		}
		else
		{
			commentsField = string.Empty;
		}
		sessionDataGUIDField = Guid.NewGuid().ToString();
	}
}
