using System;
using System.Drawing;
using ThreadSafe;

namespace OBD
{
	public class LogEventList
	{
		public int MaxEventsCount = 10000;
		public class LogEvent
		{
			public Color LogColor = Color.Navy;
			public FontStyle Style = FontStyle.Regular;
			public string[] LogStrings;
		}
		public ThreadSafeList<LogEvent> list = new ThreadSafeList<LogEvent>();
		
		public int Count
		{
			get { return list.Count; }
		}
		public LogEvent this[int index]
		{
			get
			{
				if (index >= 0 && index < Count)
					return list[index];
				return null;
			}
		}

		public void AddRecord(LogItem li)
		{
			LogEvent le = new LogEvent {LogColor = li.Color, Style = li.Style, LogStrings = new string[2]};
			le.LogStrings[0] = li.DateStr ?? "";
			le.LogStrings[1] = li.LogMessage ?? "";
			list.Insert(0,le);
			if (list.Count > MaxEventsCount)
				list.RemoveAt(list.Count - 1);
		}
		public void AddRecord(string[] strs, Color c, FontStyle fs)
		{
			if (strs != null && strs.Length > 0)
			{
				LogEvent le = new LogEvent {LogColor = c, Style = fs};
				for (int i = 0; i < strs.Length; i++)
				{
					string s = strs[i] ?? "";
				}
				list.Insert(0,le);
				if (list.Count > MaxEventsCount)
					list.RemoveAt(list.Count - 1);
			}			
		}
	}

}