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

namespace QC.CompareTestTree;

public class LoopScenarioValues
{
	private const string INPUT_PARAMETER = "INPUT";

	public const string DESCRIPTION_STRING_SEPARATOR = ";";

	private ArrayList loopConditions = new ArrayList();

	private ArrayList loopSelections = new ArrayList();

	private ArrayList loopDescriptions = new ArrayList();

	private ArrayList loopDontRunConds = new ArrayList();

	private ConditionMgr scenarioConditionMgr;

	[XmlElement(Type = typeof(LoopCondition))]
	public ArrayList LoopConditions
	{
		get
		{
			return loopConditions;
		}
		set
		{
			loopConditions = value;
		}
	}

	[XmlIgnore]
	public ArrayList DontRunCondition
	{
		get
		{
			return loopDontRunConds;
		}
		set
		{
			loopDontRunConds = value;
		}
	}

	public string DontRunConditionAsString
	{
		get
		{
			string text = "";
			if (loopDontRunConds.Count > 0)
			{
				for (int i = 0; i < loopDontRunConds.Count - 1; i++)
				{
					text = string.Concat(text, loopDontRunConds[i], ",");
				}
				text += loopDontRunConds[loopDontRunConds.Count - 1];
			}
			return text;
		}
		set
		{
			try
			{
				string[] array = value.Split(',');
				string[] array2 = array;
				foreach (string value2 in array2)
				{
					try
					{
						loopDontRunConds.Add(value2);
					}
					catch (Exception ex)
					{
						throw new Exception(ex.Message);
					}
				}
			}
			catch (Exception ex2)
			{
				throw new Exception(ex2.Message);
			}
		}
	}

	[XmlIgnore]
	public ArrayList ConditionCheck
	{
		get
		{
			return loopSelections;
		}
		set
		{
			loopSelections = value;
		}
	}

	public string ConditionCheckAsString
	{
		get
		{
			string text = "";
			if (loopSelections.Count > 0)
			{
				for (int i = 0; i < loopSelections.Count - 1; i++)
				{
					text = string.Concat(text, loopSelections[i], ",");
				}
				text += loopSelections[loopSelections.Count - 1];
			}
			return text;
		}
		set
		{
			try
			{
				string[] array = value.Split(',');
				string[] array2 = array;
				foreach (string value2 in array2)
				{
					try
					{
						loopSelections.Add(bool.Parse(value2));
					}
					catch (Exception ex)
					{
						throw new Exception(ex.Message);
					}
				}
			}
			catch (Exception ex2)
			{
				throw new Exception(ex2.Message);
			}
		}
	}

	[XmlIgnore]
	public ArrayList Descriptions
	{
		get
		{
			return loopDescriptions;
		}
		set
		{
			loopDescriptions = value;
		}
	}

	public string DescriptionsAsString
	{
		get
		{
			string text = "";
			if (loopDescriptions.Count > 0)
			{
				for (int i = 0; i < loopDescriptions.Count - 1; i++)
				{
					text = string.Concat(text, loopDescriptions[i], ";");
				}
				text += loopDescriptions[loopDescriptions.Count - 1];
			}
			return text;
		}
		set
		{
			try
			{
				string[] array = value.Split(";".ToCharArray()[0]);
				string[] array2 = array;
				foreach (string value2 in array2)
				{
					try
					{
						loopDescriptions.Add(value2);
					}
					catch (Exception ex)
					{
						throw new Exception(ex.Message);
					}
				}
			}
			catch (Exception ex2)
			{
				throw new Exception(ex2.Message);
			}
		}
	}

	[XmlIgnore]
	public int Count => loopConditions.Count;

	public ConditionMgr Condition
	{
		get
		{
			return scenarioConditionMgr;
		}
		set
		{
			scenarioConditionMgr = value;
		}
	}

	public virtual void CompareLoopScenario(string XmlTagName, LoopScenarioValues baseLoopScenario, string overrideAttrib, ref XmlDocument xmlDoc, ref XmlElement parentNode)
	{
		XmlElement parentNode2 = xmlDoc.CreateElement(XmlTagName);
		if (overrideAttrib != null)
		{
			parentNode2.SetAttribute("delta", overrideAttrib);
		}
		CommonFunctions.RootDoc = xmlDoc;
		CommonFunctions.ParentNode = parentNode2;
		for (int i = 0; i < baseLoopScenario.LoopConditions.Count; i++)
		{
			int num = -1;
			LoopCondition loopCondition = (LoopCondition)baseLoopScenario.LoopConditions[i];
			LoopCondition loopCondition2;
			for (int j = 0; j < LoopConditions.Count; j++)
			{
				loopCondition2 = (LoopCondition)LoopConditions[j];
				if (loopCondition.LoopName == loopCondition2.LoopName)
				{
					num = j;
				}
			}
			if (num < 0)
			{
				loopCondition.CompareLoopConditions("LoopConditions", loopCondition, "Remove", ref xmlDoc, ref parentNode2);
				continue;
			}
			loopCondition2 = (LoopCondition)LoopConditions[num];
			loopCondition2.CompareLoopConditions("LoopConditions", loopCondition, overrideAttrib, ref xmlDoc, ref parentNode2);
		}
		for (int i = 0; i < LoopConditions.Count; i++)
		{
			int num = -1;
			LoopCondition loopCondition2 = (LoopCondition)LoopConditions[i];
			for (int j = 0; j < baseLoopScenario.LoopConditions.Count; j++)
			{
				LoopCondition loopCondition = (LoopCondition)baseLoopScenario.LoopConditions[j];
				if (loopCondition2.LoopName == loopCondition.LoopName)
				{
					num = j;
				}
			}
			if (num < 0)
			{
				loopCondition2.CompareLoopConditions("LoopConditions", loopCondition2, "Add", ref xmlDoc, ref parentNode2);
			}
		}
		CommonFunctions.AddElement("DontRunConditionAsString", DontRunConditionAsString, baseLoopScenario.DontRunConditionAsString, overrideAttrib);
		CommonFunctions.AddElement("ConditionCheckAsString", ConditionCheckAsString, baseLoopScenario.ConditionCheckAsString, overrideAttrib);
		CommonFunctions.AddElement("DescriptionsAsString", DescriptionsAsString, baseLoopScenario.DescriptionsAsString, overrideAttrib);
		parentNode.AppendChild(parentNode2);
	}
}
