using System.Collections.Generic;
using System.Runtime.Serialization;

namespace QC.CTDS.DM.DataStructures.OutputDataStructure;

[DataContract(Namespace = "QC.CTDS.DM.DataStructures.OutputDataStructure")]
public class LinearData : OutputData
{
	private List<LinearSeriesGroup> seriesGroupList = new List<LinearSeriesGroup>();

	private List<string> xAxisValues = new List<string>();

	private double autoMinYAxis = double.NegativeInfinity;

	private double autoMaxYAxis = double.PositiveInfinity;

	private double autoMinSecYAxis = double.NegativeInfinity;

	private double autoMaxSecYAxis = double.PositiveInfinity;

	public List<LinearSeriesGroup> SeriesGroupList
	{
		get
		{
			return seriesGroupList;
		}
		set
		{
			seriesGroupList = value;
		}
	}

	[DataMember]
	public string XAxisTitle { get; set; }

	[DataMember]
	public string PrimaryYAxisTitle { get; set; }

	[DataMember]
	public string SecondaryYAxisTitle { get; set; }

	[DataMember]
	public List<string> XAxisValues
	{
		get
		{
			return xAxisValues;
		}
		set
		{
			xAxisValues = value;
		}
	}

	public double AutoMinYAxis
	{
		get
		{
			return autoMinYAxis;
		}
		set
		{
			autoMinYAxis = value;
		}
	}

	public double AutoMaxYAxis
	{
		get
		{
			return autoMaxYAxis;
		}
		set
		{
			autoMaxYAxis = value;
		}
	}

	public double AutoMinSecYAxis
	{
		get
		{
			return autoMinSecYAxis;
		}
		set
		{
			autoMinSecYAxis = value;
		}
	}

	public double AutoMaxSecYAxis
	{
		get
		{
			return autoMaxSecYAxis;
		}
		set
		{
			autoMaxSecYAxis = value;
		}
	}

	[DataMember]
	public Dictionary<string, string> SerializedYAxisAutoMinMax { get; set; }

	[DataMember]
	public List<SerializedStatisticsSeries> StatsChartSeriesList { get; set; }

	[DataMember]
	public List<ChartSeries> ChartSeriesList { get; set; }

	public void UpdateSeriesColumns()
	{
		for (int i = 0; i < seriesGroupList.Count; i++)
		{
			if (seriesGroupList[i].SeriesTbl == null || seriesGroupList[i].SeriesTbl.Rows.Count <= 0)
			{
				continue;
			}
			for (int j = 0; j < XAxisValues.Count; j++)
			{
				if (!seriesGroupList[i].SeriesTbl.Columns.Contains(XAxisValues[j]))
				{
					seriesGroupList[i].SeriesTbl.Columns.Add(XAxisValues[j]);
				}
			}
		}
	}

	public void CalculateAutoLimits()
	{
		foreach (LinearSeriesGroup seriesGroup in seriesGroupList)
		{
			if (seriesGroup.IsSecondarySeries)
			{
				if (double.IsNegativeInfinity(autoMinSecYAxis) || seriesGroup.MinYAxisVal < autoMinSecYAxis)
				{
					autoMinSecYAxis = seriesGroup.MinYAxisVal;
				}
				if (double.IsPositiveInfinity(autoMaxSecYAxis) || seriesGroup.MaxYAxisVal > autoMaxSecYAxis)
				{
					autoMaxSecYAxis = seriesGroup.MaxYAxisVal;
				}
			}
			else
			{
				if (double.IsNegativeInfinity(autoMinYAxis) || seriesGroup.MinYAxisVal < autoMinYAxis)
				{
					autoMinYAxis = seriesGroup.MinYAxisVal;
				}
				if (double.IsPositiveInfinity(autoMaxYAxis) || seriesGroup.MaxYAxisVal > autoMaxYAxis)
				{
					autoMaxYAxis = seriesGroup.MaxYAxisVal;
				}
			}
		}
	}
}
