namespace Quadarax.Foundation.Core.Logging
{
    public class ConsoleLog : ILog
    {
        private string _typeName;

        public ConsoleLog(Type owningType)
        {
            _typeName = owningType.Name;
        }

        public ConsoleLog(string owningTypeName)
        {
            _typeName = owningTypeName;
        }

        public void Log(LogSeverityEnum severity, int code, string message)
        {
			Log(severity, $"Code:{code}, {message}");            
        }

        public void Log(LogSeverityEnum severity, string message)
        {
            var now = DateTime.Now;
            var thNum = Thread.CurrentThread.ManagedThreadId;

            var final = $"[{severity}:{now.ToLongTimeString()}:{thNum}]#{_typeName}: {message}";
            Console.WriteLine(final);
        }

        public void Log(LogSeverityEnum severity, string message, Exception? exception)
        {
            Log(severity, $"{message}\n{exception}");
        }

        public void Log(LogSeverityEnum severity, int code, string message, Exception? exception)
        {
            Log(severity, string.Format("{2} - {0}\n{1}", message,exception, code));
        }
    }
}
