using System.ComponentModel;

namespace QC.QMine.QMineInterface;

public class ResultsPlugin : BasePlugin, INotifyPropertyChanged
{
	private bool isAuthenticated = true;

	private bool canProcessMessages;

	public bool IsAuthenticated
	{
		get
		{
			return isAuthenticated;
		}
		set
		{
			isAuthenticated = value;
		}
	}

	public bool CanProcessMessages
	{
		get
		{
			return canProcessMessages;
		}
		set
		{
			if (canProcessMessages != value)
			{
				canProcessMessages = value;
				OnPropertyChanged("CanProcessMessages");
			}
		}
	}

	public event PropertyChangedEventHandler PropertyChanged;

	protected virtual void OnPropertyChanged(string propertyName)
	{
		PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
		if (propertyChanged != null)
		{
			PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
			propertyChanged(this, e);
		}
	}

	public override void MessageFromQMine(QMineMessage msg)
	{
		base.MessageFromQMine(msg);
		if (msg != null)
		{
			if (msg.MessageType == QMineMessageType.SaveConfiguration)
			{
				base.Configuration.AddNewConfiguration("CanProcessMessages", CanProcessMessages.ToString());
			}
			else if (msg.MessageType == QMineMessageType.LoadConfiguration)
			{
				string configurationValue = base.Configuration.GetConfigurationValue("CanProcessMessages");
				bool result = CanProcessMessages;
				bool.TryParse(configurationValue, out result);
				CanProcessMessages = result;
			}
		}
	}
}
