using System;
using SlatedGameToolkit.Framework.Logging;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;

namespace SlatedGameToolkit.Tools.Utilities.Playground
{
    public class ConsoleLogListener : ILogListener
    {

        public bool Debug { get; set; }
        public LogLevel Level => Debug ? LogLevel.DEBUG : LogLevel.INFO;
        private ConsoleInteraction interaction;

        public ConsoleLogListener(ConsoleInteraction interaction = null) {
            this.interaction = interaction;
        }
        
        public void LogMesesage(string message, DateTime time, LogLevel level)
        {
            Console.SetCursorPosition(0, Console.CursorTop);
            Console.WriteLine(string.Format("Playground [{0}] [{1}]: {2}", level, time.ToString("H:mm:ss"), message));
            if (interaction != null && interaction.Listening) {
                Console.SetCursorPosition(0, Console.CursorTop);
                Console.Write(interaction.Prefix + "> ");
            }
        }
    }
}