using System;
using System.Collections.Generic;

namespace SlatedGameToolkit.Framework.Logging
{
    public static class Logger {
        private static HashSet<ILogListener> listeners = new HashSet<ILogListener>();

        /// <summary>
        /// Logs the message to listeners that are listening to the set severity of the message or greater.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="level">The level of severity, by defeault, info.</param>
        public static void Log(string message, LogLevel level = LogLevel.INFO) {
            foreach (ILogListener listener in listeners)
            {
                if (level <= listener.Level) {
                    listener.LogMesesage(message, DateTime.Now, level);
                }
            }
        }

        /// <summary>
        /// Adds a log listener.
        /// </summary>
        /// <param name="listener">The listener to add.</param>
        public static void AddLogListener(ILogListener listener) {
            listeners.Add(listener);
        }

        /// <summary>
        /// Removes a log listener.
        /// </summary>
        /// <param name="listener">The listener to remove.</param>
        public static void RemoveLogListener(ILogListener  listener) {
            listeners.Remove(listener);
        }

        /// <summary>
        /// Called when all listeners should perform any flushing they need.
        /// </summary>
        public static void FlushListeners() {

        }
    }
}