using System.Runtime.CompilerServices;
using AyCode.Core.Enums;
using AyCode.Core.Loggers;

namespace AyCode.Core.Server.Loggers
{
    public sealed class AcGlobalLoggerBase : AcLoggerBase
    { }

    public sealed class GlobalLogger //: IAcLogWriterBase
    {
        private readonly AcGlobalLoggerBase _logger = new();
        private static readonly GlobalLogger Instance = new();

        public static LogLevel LogLevel => Instance._logger.LogLevel;
        public static AppType AppType => Instance._logger.AppType;
        
        private const string DefaultCategoryName = "GLOBAL_LOGGER";

        static GlobalLogger()
        { }

        private GlobalLogger()
        { }


        public static List<IAcLogWriterBase> GetWriters => Instance._logger.GetWriters;
        public static TLogWriter? Writer<TLogWriter>() where TLogWriter : IAcLogWriterBase => Instance._logger.Writer<TLogWriter>();


        public static void Detail(string? text, string? categoryName = null, [CallerMemberName] string? memberName = null) 
            => Instance._logger.Detail(text, categoryName ?? DefaultCategoryName, memberName);

        //public static void Detail<TCallerClassType>(string? text, [CallerMemberName] string? memberName = null) where TCallerClassType : class
        //    => Detail(text, typeof(TCallerClassType).Name, memberName);

        public static void Debug(string? text, string? categoryName = null, [CallerMemberName] string? memberName = null) 
            => Instance._logger.Debug(text, categoryName ?? DefaultCategoryName, memberName);

        //public static void Debug<TCallerClassType>(string? text, [CallerMemberName] string? memberName = null) where TCallerClassType : class
        //    => Debug(text, typeof(TCallerClassType).Name, memberName);

        public static void Info(string? text, string? categoryName = null, [CallerMemberName] string? memberName = null) 
            => Instance._logger.Info(text, categoryName ?? DefaultCategoryName, memberName);

        //public static void Info<TCallerClassType>(string? text, [CallerMemberName] string? memberName = null) where TCallerClassType : class
        //    => Info(text, typeof(TCallerClassType).Name, memberName);

        public static void Warning(string? text, string? categoryName = null, [CallerMemberName] string? memberName = null) 
            => Instance._logger.Warning(text, categoryName ?? DefaultCategoryName, memberName);

        //public static void Warning<TCallerClassType>(string? text, [CallerMemberName] string? memberName = null) where TCallerClassType : class
        //    => Warning(text, typeof(TCallerClassType).Name, memberName);

        public static void Suggest(string? text, string? categoryName = null, [CallerMemberName] string? memberName = null) 
            => Instance._logger.Suggest(text, categoryName ?? DefaultCategoryName, memberName);

        //public static void Suggest<TCallerClassType>(string? text, [CallerMemberName] string? memberName = null) where TCallerClassType : class
        //    => Suggest(text, typeof(TCallerClassType).Name, memberName);

        //public static void Error<TCallerClassType>(string? text, Exception? ex = null, [CallerMemberName] string? memberName = null) where TCallerClassType : class
        //    => Error(text, ex, typeof(TCallerClassType).Name, memberName);

        public static void Error(string? text, Exception? ex = null, string? categoryName = null, [CallerMemberName] string? memberName = null) 
            => Instance._logger.Error(text, ex, categoryName ?? DefaultCategoryName, memberName);

        public static void Write(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName)
            => Write(appType, logLevel, logText, callerMemberName, categoryName, null, null);

        public static void Write(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, Exception? ex)
            => Write(appType, logLevel, logText, callerMemberName, categoryName, ex?.GetType().Name, ex?.ToString());

        public static void Write(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
            => Instance._logger.Write(appType, logLevel, logText, callerMemberName, categoryName, errorType, exMessage);
    }
}
