using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
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 StatsResultsBin : DiscriminatorElement
{
	private ObservableCollection<StatisticsResultDataSet> statsResult = new ObservableCollection<StatisticsResultDataSet>();

	private string format = "0.00";

	private bool _sort;

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

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

	[XmlAttribute]
	[DefaultValue(false)]
	public bool sort
	{
		get
		{
			return _sort;
		}
		set
		{
			if (_sort != value)
			{
				_sort = value;
				base.OnPropertyChanged("sort");
			}
		}
	}

	public StatsResultsBin()
	{
		StatsResult.CollectionChanged += EstablishParentChildRelationOnCollectionChanged;
		StatsResult.CollectionChanged += StatsResult_CollectionChanged;
	}

	public StatsResultsBin(StatsResultsBin statsBin)
		: base(statsBin)
	{
		statsResult = new ObservableCollection<StatisticsResultDataSet>();
		foreach (StatisticsResultDataSet item in statsBin.statsResult)
		{
			statsResult.Add(new StatisticsResultDataSet(item));
		}
	}

	private void StatsResult_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
	{
		OnPropertyChanged("StatsResult");
	}

	public void CreateNewStatsResult()
	{
		StatisticsResultDataSet statisticsResultDataSet = new StatisticsResultDataSet();
		statisticsResultDataSet.resID = "ParameterName";
		statisticsResultDataSet.testID = "TestName";
		statisticsResultDataSet.IsSelected = true;
		StatsResult.Add(statisticsResultDataSet);
	}

	public List<string> GetTestNames()
	{
		List<string> testNames = new List<string>();
		StatsResult.ForEach(delegate(StatisticsResultDataSet res)
		{
			testNames.Add(res.testID);
		});
		return testNames.Distinct().ToList();
	}
}
