using System;
using System.Collections.Generic;
using System.Linq;
using QC.CTDS.DM.DataStructures;
using QC.CTDS.DM.DataStructures.FormatDescriptorStructure;

namespace QC.CTDS.DM.DataProcessor;

public static class DescriptorProcessorFactory
{
	public static IDescriptorProcessor CreateDescriptorProcessor(GroupSetDescriptor groupDesc, List<string> enabledCharts)
	{
		if (groupDesc.GetType() == typeof(CondensedSummary))
		{
			return ApplyEnabledChartTypesFilter(enabledCharts, "CondensedSummary", new CondensedSummaryProcessor());
		}
		if (groupDesc.GetType() == typeof(LineOutputGroupDescriptor))
		{
			return ApplyEnabledChartTypesFilter(enabledCharts, "LineChart", new LineDescriptorProcessor());
		}
		if (groupDesc.GetType() == typeof(HistogramOutputGroupDescriptor))
		{
			return ApplyEnabledChartTypesFilter(enabledCharts, "HistogramChart", new HistogramDescriptorProcessor());
		}
		if (groupDesc.GetType() == typeof(ScatterOutputGroupDescriptor))
		{
			return ApplyEnabledChartTypesFilter(enabledCharts, "ScatteredChart", new ScatteredDescriptorProcessor());
		}
		if (groupDesc.GetType() == typeof(WideCondensedSummary))
		{
			return ApplyEnabledChartTypesFilter(enabledCharts, "WideSummary", new WideSummaryProcessor());
		}
		if (groupDesc.GetType() == typeof(MultiDimensionOutputGroupDescriptor))
		{
			return ApplyEnabledChartTypesFilter(enabledCharts, "MultiDimensionChart", new MultiDimensionDescriptorProcessor());
		}
		return null;
	}

	private static IDescriptorProcessor ApplyEnabledChartTypesFilter(List<string> enabledCharts, string currentChart, IDescriptorProcessor descProcessor)
	{
		if (enabledCharts.Count > 0)
		{
			if (enabledCharts.Contains(currentChart, StringComparer.OrdinalIgnoreCase))
			{
				return descProcessor;
			}
			return null;
		}
		return descProcessor;
	}
}
