using System;
using System.Text;
using System.Windows;

namespace QC.QMine.QMineInterface;

public class OutputLog : BindableObject, IDisposable
{
	private StringBuilder outputStringBuilder = new StringBuilder();

	public string DisplayName { get; set; }

	public string RunLogMessageCollection => outputStringBuilder.ToString();

	public void WriteLogMessage(string message, bool newLine = true)
	{
		if (!string.IsNullOrWhiteSpace(message))
		{
			Action<string> action = null;
			if (newLine)
			{
				message = "\n" + DateTime.Now.ToString() + " >> " + message;
			}
			action = AddMessageToCollection;
			Application.Current.Dispatcher.Invoke(action, message);
			OnPropertyChanged("RunLogMessageCollection");
		}
	}

	private void AddMessageToCollection(string message)
	{
		outputStringBuilder.Append(message);
	}

	public void Dispose()
	{
		outputStringBuilder.Length = 0;
	}
}
