using System.Collections.Generic;
using UnityEngine;

namespace CoolGameX
{
    /// <summary>Console logging with levels, plus a short history for the debug overlay.</summary>
    internal static class Log
    {
        private const string Prefix = "[CoolAPI] ";
        private const int Keep = 40;
        private static readonly Queue<string> recent = new Queue<string>();

        /// <summary>The most recent SDK log lines, oldest first (for the debug overlay).</summary>
        internal static string[] Recent => recent.ToArray();

        internal static void Verbose(string message) { Push("·", message); if (CoolAPI.LogLevel >= CGXLogLevel.Verbose) Debug.Log(Prefix + message); }
        internal static void Info(string message) { Push("i", message); if (CoolAPI.LogLevel >= CGXLogLevel.Info) Debug.Log(Prefix + message); }
        internal static void Warn(string message) { Push("!", message); if (CoolAPI.LogLevel >= CGXLogLevel.Warnings) Debug.LogWarning(Prefix + message); }
        internal static void Error(string message) { Push("×", message); if (CoolAPI.LogLevel >= CGXLogLevel.Errors) Debug.LogError(Prefix + message); }

        private static void Push(string tag, string message)
        {
            recent.Enqueue($"{System.DateTime.Now:HH:mm:ss} {tag} {message}");
            while (recent.Count > Keep) recent.Dequeue();
        }

        internal static void Clear() => recent.Clear();
    }
}
