using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using QC.QMine.QMineInterface;

namespace QC.QMine;

[Serializable]
public class PluginSettings
{
	private List<PluginConfiguration> pluginConfigCollection = new List<PluginConfiguration>();

	private string filePath;

	public List<PluginConfiguration> PluginConfigCollection
	{
		get
		{
			return pluginConfigCollection;
		}
		set
		{
			pluginConfigCollection = value;
		}
	}

	[XmlIgnore]
	public string FilePath
	{
		get
		{
			return filePath;
		}
		set
		{
			filePath = value;
		}
	}

	public PluginConfiguration FindPluginConfiguration(string pluginName)
	{
		PluginConfiguration pluginConfiguration = PluginConfigCollection.Find((PluginConfiguration pluginConfig) => pluginConfig.PluginName == pluginName);
		if (pluginConfiguration == null)
		{
			PluginConfiguration pluginConfiguration2 = new PluginConfiguration();
			pluginConfiguration2.PluginName = pluginName;
			pluginConfiguration = pluginConfiguration2;
		}
		return pluginConfiguration;
	}

	public void UpdatePluginConfigurations(IEnumerable<PluginConfiguration> pluginConfigs)
	{
		foreach (PluginConfiguration config in pluginConfigs)
		{
			List<PluginConfiguration> list = pluginConfigCollection;
			Predicate<PluginConfiguration> match = (PluginConfiguration pluginConfig) => pluginConfig.PluginName == config.PluginName;
			PluginConfiguration pluginConfiguration = list.Find(match);
			if (pluginConfiguration == null)
			{
				pluginConfigCollection.Add(config);
				continue;
			}
			pluginConfigCollection.Remove(pluginConfiguration);
			pluginConfigCollection.Add(config);
		}
	}
}
