using System;
using System.Collections.Generic;
using System.Text;

namespace QCRPG.Framework;

public class LogMessage : IDeepCopyable<LogMessage>
{
	public LogMessageType Type;

	public DateTime Timestamp;

	public List<string> Lines = new List<string>();

	public List<string> ConciseLines;

	public string TechnologyName;

	public string DutName;

	public LogMessage(LogMessageType type)
	{
		Type = type;
		Timestamp = DateTime.Now;
		Lines.Clear();
		ConciseLines = Lines;
	}

	public LogMessage(LogMessageType type, string text)
	{
		Type = type;
		Timestamp = DateTime.Now;
		Lines.Clear();
		Lines.Add(text);
		ConciseLines = Lines;
	}

	public LogMessage(LogMessageType type, Exception ex)
	{
		Type = type;
		Timestamp = DateTime.Now;
		string text;
		if (ex.StackTrace == null)
		{
			text = "an unknown method.";
		}
		else
		{
			string[] array = ex.StackTrace.Replace(" at ", "  ").Split(new char[2] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
			text = array[0].Trim();
		}
		string text2 = ex.Message.Trim();
		Lines.Clear();
		Lines.Add("Caught exception in " + text);
		Lines.AddRange(text2.Split('\r', '\n'));
		if (ex.StackTrace != null)
		{
			Lines.Add("Full stack trace: " + ex.StackTrace);
		}
		ConciseLines = Lines;
	}

	public LogMessage(LogMessageType type, List<string> stringList)
	{
		Type = type;
		Timestamp = DateTime.Now;
		Lines.Clear();
		foreach (string @string in stringList)
		{
			Lines.Add(@string);
		}
		ConciseLines = Lines;
	}

	public LogMessage(LogMessageType type, string[] stringArray)
	{
		Type = type;
		Timestamp = DateTime.Now;
		Lines.Clear();
		foreach (string item in stringArray)
		{
			Lines.Add(item);
		}
		ConciseLines = Lines;
	}

	public void AppendLine(string text)
	{
		Lines.Add(text);
	}

	public void AppendLines(List<string> lines)
	{
		Lines.AddRange(lines);
	}

	public void AppendLines(string[] lines)
	{
		Lines.AddRange(lines);
	}

	public virtual LogMessage DeepCopy()
	{
		LogMessage logMessage = new LogMessage(Type);
		logMessage.Timestamp = Timestamp;
		foreach (string line in Lines)
		{
			logMessage.Lines.Add(line);
		}
		logMessage.TechnologyName = TechnologyName;
		logMessage.DutName = DutName;
		logMessage.ConciseLines = ConciseLines;
		return logMessage;
	}

	public override string ToString()
	{
		StringBuilder stringBuilder = new StringBuilder();
		foreach (string line in Lines)
		{
			stringBuilder.AppendLine(line);
		}
		return stringBuilder.ToString();
	}
}
