using System.Windows.Controls;

namespace QC.QMine.QMineInterface;

public abstract class BasePlugin
{
	public delegate void MessageToQMineEventHandler(PluginConfiguration pluginInfo, QMineMessage msg);

	public delegate void WriteLogEventHandler(PluginConfiguration pluginInfo, string message, LogType logType = LogType.Notification);

	public delegate void ShowMessageEventHandler(PluginConfiguration pluginInfo, string message);

	public delegate void WriteStatusEventHandler(PluginConfiguration pluginInfo, string message);

	public delegate void ShowHelpEventHandler(string message);

	private string pluginName;

	private UserControl userInterface;

	private PluginConfiguration configuration = new PluginConfiguration();

	private bool isSelected;

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

	public virtual UserControl UserInterface
	{
		get
		{
			return userInterface;
		}
		set
		{
			userInterface = value;
		}
	}

	public PluginConfiguration Configuration
	{
		get
		{
			return configuration;
		}
		set
		{
			configuration = value;
		}
	}

	public bool IsSelected
	{
		get
		{
			return isSelected;
		}
		set
		{
			isSelected = value;
		}
	}

	public event MessageToQMineEventHandler OnMessageToQMine;

	public event WriteLogEventHandler OnWriteLog;

	public event ShowMessageEventHandler OnShowMessage;

	public event WriteStatusEventHandler OnWriteStatus;

	public event ShowHelpEventHandler OnShowHelp;

	public BasePlugin()
	{
	}

	public virtual void MessageFromQMine(QMineMessage msg)
	{
		if (msg == null)
		{
			return;
		}
		switch (msg.MessageType)
		{
		case QMineMessageType.LoadConfiguration:
		{
			PluginConfiguration dataInType = msg.GetDataInType<PluginConfiguration>();
			if (dataInType != null)
			{
				Configuration = dataInType;
			}
			break;
		}
		case QMineMessageType.SaveConfiguration:
			msg.Data = Configuration;
			break;
		case QMineMessageType.ResetConfiguration:
			Configuration = new PluginConfiguration(PluginName);
			break;
		}
	}

	protected virtual void MessageToQMine(QMineMessage msg)
	{
		if (this.OnMessageToQMine != null)
		{
			this.OnMessageToQMine(Configuration, msg);
		}
	}

	protected virtual void WriteLog(string message, LogType logType = LogType.Notification)
	{
		if (this.OnWriteLog != null)
		{
			this.OnWriteLog.BeginInvoke(Configuration, message, logType, null, null);
		}
	}

	protected virtual void ShowMessage(string message)
	{
		if (this.OnShowMessage != null)
		{
			this.OnShowMessage(Configuration, message);
		}
	}

	protected virtual void WriteStatus(string message)
	{
		if (this.OnWriteStatus != null)
		{
			this.OnWriteStatus(Configuration, message);
		}
	}

	protected virtual void ShowHelp(string message)
	{
		if (this.OnShowHelp != null)
		{
			this.OnShowHelp(message);
		}
	}
}
