using System;
using System.Collections.Generic;

namespace QC.QMine.QMineInterface;

[Serializable]
public class PluginConfiguration
{
	private string pluginName;

	private List<PluginConfigItem> pluginConfigItems = new List<PluginConfigItem>();

	public string PluginName
	{
		get
		{
			return pluginName;
		}
		set
		{
			pluginName = value;
		}
	}

	public List<PluginConfigItem> PluginConfigItems => pluginConfigItems;

	public PluginConfiguration(string pluginName)
	{
		this.pluginName = pluginName;
	}

	public PluginConfiguration()
		: this("<Unknown plugin>")
	{
	}

	public void AddNewConfiguration(string name, string value)
	{
		PluginConfigItem pluginConfigItem = FindConfigItem(name);
		if (pluginConfigItem == null)
		{
			pluginConfigItems.Add(new PluginConfigItem
			{
				ConfigName = name,
				ConfigValue = value
			});
		}
		else
		{
			pluginConfigItem.ConfigValue = value;
		}
	}

	public string GetConfigurationValue(string name)
	{
		return FindConfigItem(name)?.ConfigValue;
	}

	private PluginConfigItem FindConfigItem(string name)
	{
		return pluginConfigItems.Find((PluginConfigItem pluginConfig) => pluginConfig.ConfigName.ToLower() == name.ToLower());
	}
}
