using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace QC.QSPRLogSchema;

public static class RunExtensions
{
	public static bool SaveToXML(this Run run, string path)
	{
		XmlSerializer xmlSerializer = new XmlSerializer(typeof(Run));
		using (FileStream output = new FileStream(path, FileMode.OpenOrCreate))
		{
			using XmlWriter xmlWriter = XmlWriter.Create(output, new XmlWriterSettings
			{
				Indent = false
			});
			xmlSerializer.Serialize(xmlWriter, run);
		}
		return true;
	}

	public static bool HasNullStartTime(this Run run)
	{
		foreach (Test item in run.TestCollection)
		{
			if (string.IsNullOrWhiteSpace(item.StartTime))
			{
				return true;
			}
		}
		return false;
	}
}
