using System.Collections.Generic;
using UnityEngine;

namespace gay.lilyy.logger
{
    public enum LogLevel
    {
        Info,
        Warning,
        Error,
        Success,
        Debug
    }

    public abstract class BaseLogger
    {
        protected abstract string SystemName { get; }
        protected abstract Dictionary<LogLevel, string> LogColors { get; }
        protected abstract Dictionary<LogLevel, string> LogPrefixes { get; }

        public virtual void Log(LogLevel level, string message, Object context = null)
        {
            string color = LogColors.ContainsKey(level) ? LogColors[level] : "#FFFFFF";
            string prefix = LogPrefixes.ContainsKey(level) ? LogPrefixes[level] + " " : "";
            string styledMessage = $"<color={color}>{prefix}[{SystemName}] {message}</color>";
            
            switch (level)
            {
                case LogLevel.Info:
                    UnityEngine.Debug.Log(styledMessage, context);
                    break;
                case LogLevel.Warning:
                    UnityEngine.Debug.LogWarning(styledMessage, context);
                    break;
                case LogLevel.Error:
                    UnityEngine.Debug.LogError(styledMessage, context);
                    break;
                case LogLevel.Success:
                    UnityEngine.Debug.Log(styledMessage, context);
                    break;
                case LogLevel.Debug:
                    UnityEngine.Debug.Log(styledMessage, context);
                    break;
            }
        }

        public virtual void Info(string message, Object context = null) => Log(LogLevel.Info, message, context);
        public virtual void Warning(string message, Object context = null) => Log(LogLevel.Warning, message, context);
        public virtual void Error(string message, Object context = null) => Log(LogLevel.Error, message, context);
        public virtual void Success(string message, Object context = null) => Log(LogLevel.Success, message, context);
        public virtual void Debug(string message, Object context = null) => Log(LogLevel.Debug, message, context);
    }
}
