﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GLogUnity
{
	[Serializable]
	public class LogInfo
	{
		public System.DateTime time;
		public VerboseLevel level;
		public string tag1 = null;
		public string tag2 = null;
		public string tag3 = null;
		public string message = null;

		/// <summary>Defines a log message or the Log Channel.
		/// <para>For log record keeping it is advised to use the tags, and make the message consistent to allow batch processing</para>
		/// </summary>
		/// <param name="tagsAndMessage">List of tags (up to three) and message </param>
		public LogInfo(VerboseLevel level, params string[] tagsAndMessage)
		{
			this.time = System.DateTime.Now;
			this.level = level;
			if (tagsAndMessage.Length == 4)
			{
				this.tag1 = tagsAndMessage[0];
				this.tag2 = tagsAndMessage[1];
				this.tag3 = tagsAndMessage[2];
				this.message = tagsAndMessage[3];
			}
			else if (tagsAndMessage.Length == 3)
			{
				this.tag1 = tagsAndMessage[0];
				this.tag2 = tagsAndMessage[1];
				this.message = tagsAndMessage[2];
			}
			else if (tagsAndMessage.Length == 2)
			{
				this.tag1 = tagsAndMessage[0];
				this.message = tagsAndMessage[1];
			}
			else if (tagsAndMessage.Length == 1)
			{
				this.message = tagsAndMessage[0];
			}
			else
			{
				throw new System.Exception("Missing a log message");
			}
		}

		public string GetJSON()
		{
			return $"{{\"time\":\"{time.ToString("yyyy-MM-dd HH:mm:ss")}\",\"tag1\":\"{GLog.VerboseLevelString(level)}\",\"tag2\":\"{tag1}\",\"tag3\":\"{tag2}\",\"tag4\":\"{tag3}\",\"data\":\"{message}\"}}";
		}
	}
}
