using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Xml.Schema;
using System.Xml.Serialization;
using QC.CTDS.DM.SharedLibrary;

namespace QC.CTDS.DM.DataStructures.FormatDescriptorStructure;

[Serializable]
public class MultiDimensionOutputGroupDescriptor : ChartOutputGroupDescriptor
{
	private ObservableCollection<MultiDimensionResult> multiDimensions = new ObservableCollection<MultiDimensionResult>();

	private string _xName;

	private string _yName;

	private string _zName;

	[XmlElement("MultiDimensionResultSet", Form = XmlSchemaForm.Unqualified)]
	public ObservableCollection<MultiDimensionResult> MultiDimensionResultSet
	{
		get
		{
			return multiDimensions;
		}
		set
		{
			if (multiDimensions != value)
			{
				multiDimensions = value;
				OnPropertyChanged("MultiDimensionResultSet");
			}
		}
	}

	[XmlAttribute]
	public string xName
	{
		get
		{
			return _xName;
		}
		set
		{
			if (!(_xName == value))
			{
				_xName = value;
				OnPropertyChanged("xName");
			}
		}
	}

	[XmlAttribute]
	public string yName
	{
		get
		{
			return _yName;
		}
		set
		{
			if (!(_yName == value))
			{
				_yName = value;
				OnPropertyChanged("yName");
			}
		}
	}

	[XmlAttribute]
	public string zName
	{
		get
		{
			return _zName;
		}
		set
		{
			if (!(_zName == value))
			{
				_zName = value;
				OnPropertyChanged("zName");
			}
		}
	}

	public override string this[string columnName]
	{
		get
		{
			string result = null;
			if (columnName == "xName" && string.IsNullOrEmpty(xName))
			{
				result = "X Axis name cannot be null or empty";
			}
			if (columnName == "yName" && string.IsNullOrEmpty(yName))
			{
				result = "Y Axis name cannot be null or empty";
			}
			if (columnName == "zName" && string.IsNullOrEmpty(yName))
			{
				result = "Z Axis name cannot be null or empty";
			}
			return result;
		}
	}

	public MultiDimensionOutputGroupDescriptor()
	{
		MultiDimensionResultSet.CollectionChanged += EstablishParentChildRelationOnCollectionChanged;
		MultiDimensionResultSet.CollectionChanged += MultiDimensionResults_CollectionChanged;
	}

	private void MultiDimensionResults_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
	{
		OnPropertyChanged("MultiDimensionResultSet");
	}

	public void CreateNewMultiDimensionResult(string xAxis, string yAxis, string zAxis, string testID)
	{
		MultiDimensionResult multiDimensionResult = new MultiDimensionResult();
		MultiDimensionResultSet.Add(multiDimensionResult);
		multiDimensionResult.testID = testID;
		multiDimensionResult.resID = yAxis;
		multiDimensionResult.XAxis = new ChartDimension
		{
			AxisId = xAxis,
			Discriminator1 = new ObservableCollection<Discriminator>
			{
				new Discriminator
				{
					id = xAxis
				}
			}
		};
		multiDimensionResult.ZAxis = new ChartDimension
		{
			AxisId = zAxis,
			Discriminator1 = new ObservableCollection<Discriminator>
			{
				new Discriminator
				{
					id = zAxis
				}
			}
		};
	}

	public void CreateNewMultiDimensionResult()
	{
		MultiDimensionResult multiDimensionResult = new MultiDimensionResult();
		MultiDimensionResultSet.Add(multiDimensionResult);
		multiDimensionResult.testID = "ResultSet " + MultiDimensionResultSet.IndexOf(multiDimensionResult);
		multiDimensionResult.resID = "YParameter " + MultiDimensionResultSet.IndexOf(multiDimensionResult);
		multiDimensionResult.XAxis = new ChartDimension
		{
			AxisId = "XParameter"
		};
		multiDimensionResult.ZAxis = new ChartDimension
		{
			AxisId = "ZParameter"
		};
	}

	public override List<string> GetTestNames()
	{
		List<string> testNames = new List<string>();
		MultiDimensionResultSet.ForEach(delegate(MultiDimensionResult resultSet)
		{
			testNames.Add(resultSet.testID);
		});
		return testNames.Distinct().ToList();
	}

	internal override void ApplyFileGrouping(IEnumerable<string> groupNames)
	{
		List<MultiDimensionResult> groupedResultSetColl = new List<MultiDimensionResult>();
		foreach (MultiDimensionResult item in MultiDimensionResultSet.Where((MultiDimensionResult ser) => !Constants.AllTestsString.Contains(ser.testID)))
		{
			foreach (string groupName in groupNames)
			{
				MultiDimensionResult multiDimensionResult = new MultiDimensionResult(item);
				multiDimensionResult.testID = multiDimensionResult.testID + "_" + groupName;
				multiDimensionResult.GroupName = groupName;
				groupedResultSetColl.Add(multiDimensionResult);
			}
		}
		groupedResultSetColl.RemoveAll((MultiDimensionResult ser) => !Constants.AllTestsString.Contains(ser.testID));
		groupedResultSetColl.ForEach(delegate(MultiDimensionResult series)
		{
			groupedResultSetColl.Add(series);
		});
	}

	internal override void RemoveFileGrouping(IEnumerable<string> groupNames)
	{
		HashSet<string> hashSet = new HashSet<string>();
		List<MultiDimensionResult> list = new List<MultiDimensionResult>();
		foreach (MultiDimensionResult item in MultiDimensionResultSet.Where((MultiDimensionResult res) => !Constants.AllTestsString.Contains(res.testID)))
		{
			foreach (string groupName in groupNames)
			{
				if (item.testID.EndsWith("_" + groupName))
				{
					string text = item.testID.Replace("_" + groupName, "");
					if (!hashSet.Contains(text + item.resID))
					{
						hashSet.Add(text + item.resID);
						item.testID = text;
						list.Add(item);
					}
				}
			}
		}
		MultiDimensionResultSet.RemoveAll((MultiDimensionResult res) => !Constants.AllTestsString.Contains(res.testID));
		list.ForEach(delegate(MultiDimensionResult resultSet)
		{
			MultiDimensionResultSet.Add(resultSet);
		});
	}

	public override IEnumerable<ResultDataSet> GetResultSets()
	{
		List<ResultDataSet> list = new List<ResultDataSet>();
		foreach (MultiDimensionResult item in MultiDimensionResultSet)
		{
			if (item.resID != null && !string.IsNullOrEmpty(item.resID))
			{
				ResultDataSet resultDataSet = new ResultDataSet();
				resultDataSet.testID = item.testID;
				resultDataSet.resID = item.resID;
				list.Add(resultDataSet);
			}
		}
		return list;
	}

	internal override void ApplyGroupPrefix(Discriminator discriminator)
	{
		if (discriminator != null)
		{
			MultiDimensionResultSet.ForEach(delegate(MultiDimensionResult res)
			{
				res.PrefixDiscriminator(discriminator);
			});
		}
	}
}
