using System;
using System.Xml;

namespace QC.CompareTestTree;

internal class Statistics
{
	public static int addCount;

	public static int removeCount;

	public static int matchCount;

	public static int changeCount;

	public static int totalCount;

	public static int currentAddCount;

	public static int currentRemoveCount;

	public static int currentMatchCount;

	public static int currentChangeCount;

	public static int currentTotalCount;

	public static int AddCount
	{
		get
		{
			return addCount;
		}
		set
		{
			addCount = value;
		}
	}

	public static int MatchCount
	{
		get
		{
			return matchCount;
		}
		set
		{
			matchCount = value;
		}
	}

	public static int RemoveCount
	{
		get
		{
			return removeCount;
		}
		set
		{
			removeCount = value;
		}
	}

	public static int ChangeCount
	{
		get
		{
			return changeCount;
		}
		set
		{
			changeCount = value;
		}
	}

	public static int TotalCount
	{
		get
		{
			return totalCount;
		}
		set
		{
			totalCount = value;
		}
	}

	public static int CurrentAddCount
	{
		get
		{
			return currentAddCount;
		}
		set
		{
			currentAddCount = value;
		}
	}

	public static int CurrentMatchCount
	{
		get
		{
			return currentMatchCount;
		}
		set
		{
			currentMatchCount = value;
		}
	}

	public static int CurrentRemoveCount
	{
		get
		{
			return currentRemoveCount;
		}
		set
		{
			currentRemoveCount = value;
		}
	}

	public static int CurrentChangeCount
	{
		get
		{
			return currentChangeCount;
		}
		set
		{
			currentChangeCount = value;
		}
	}

	public static int CurrentTotalCount
	{
		get
		{
			return currentTotalCount;
		}
		set
		{
			currentTotalCount = value;
		}
	}

	public static void DetermineStatics(XmlNode parentNode, ref XmlDocument xmlDoc, ref XmlElement rootNode)
	{
		CurrentAddCount = (CurrentRemoveCount = (CurrentMatchCount = (CurrentChangeCount = (CurrentTotalCount = 0))));
		XmlNodeList childNodes = parentNode.ChildNodes;
		for (int i = 0; i < childNodes.Count; i++)
		{
			try
			{
				if (childNodes[i].Attributes["delta"] != null)
				{
					CurrentTotalCount++;
					switch (childNodes[i].Attributes["delta"].Value)
					{
					case "Add":
						CurrentAddCount++;
						break;
					case "Change":
						CurrentChangeCount++;
						break;
					case "Match":
						CurrentMatchCount++;
						break;
					case "Remove":
						CurrentRemoveCount++;
						break;
					}
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}
		XmlElement xmlElement = xmlDoc.CreateElement("Add");
		xmlElement.InnerText = CurrentAddCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("Change");
		xmlElement.InnerText = CurrentChangeCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("Remove");
		xmlElement.InnerText = CurrentRemoveCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("Match");
		xmlElement.InnerText = CurrentMatchCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("TotalCount");
		xmlElement.InnerText = CurrentTotalCount.ToString();
		rootNode.AppendChild(xmlElement);
		TotalCount += CurrentTotalCount;
		AddCount += CurrentAddCount;
		ChangeCount += CurrentChangeCount;
		RemoveCount += CurrentRemoveCount;
		MatchCount += CurrentMatchCount;
	}

	public static void GlobalStatistic(ref XmlDocument xmlDoc, ref XmlElement rootNode)
	{
		XmlElement xmlElement = xmlDoc.CreateElement("Add");
		xmlElement.InnerText = AddCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("Change");
		xmlElement.InnerText = ChangeCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("Remove");
		xmlElement.InnerText = RemoveCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("Match");
		xmlElement.InnerText = MatchCount.ToString();
		rootNode.AppendChild(xmlElement);
		xmlElement = xmlDoc.CreateElement("TotalCount");
		xmlElement.InnerText = TotalCount.ToString();
		rootNode.AppendChild(xmlElement);
	}

	public static void GlobalStatistic(XmlNode parentNode)
	{
		if (parentNode.HasChildNodes)
		{
			XmlNodeList childNodes = parentNode.ChildNodes;
			for (int i = 0; i < childNodes.Count; i++)
			{
				GlobalStatistic(childNodes[i]);
			}
		}
		try
		{
			if (parentNode.Attributes["delta"] != null)
			{
				TotalCount++;
				switch (parentNode.Attributes["delta"].Value)
				{
				case "Add":
					AddCount++;
					break;
				case "Change":
					ChangeCount++;
					break;
				case "Match":
					MatchCount++;
					break;
				case "Remove":
					RemoveCount++;
					break;
				}
			}
		}
		catch (Exception ex)
		{
			throw new Exception(ex.Message, ex);
		}
	}

	public static void ResetCount()
	{
		CurrentAddCount = (CurrentRemoveCount = (CurrentMatchCount = (CurrentChangeCount = (CurrentTotalCount = 0))));
		AddCount = (RemoveCount = (MatchCount = (ChangeCount = (TotalCount = 0))));
	}
}
