using AyCode.Core.Consts;
using AyCode.Core.Loggers;
using AyCode.Entities.Server.LogItems;
using Castle.Core.Logging;
using Microsoft.AspNetCore.SignalR;

namespace AyCode.Services.Server.SignalRs;


public class AcLoggerSignalRHub<TLogger>(TLogger logger) : Hub where TLogger : IAcLoggerBase
{
    private TLogger _logger = logger;

    public void AddLogItem(AcLogItem? logItem)
    {
        try
        {
            if (logItem == null)
            {
                _logger.Error("AddLogItem; LogItem == null");
                //_logger.Writer<ConsoleLogWriter>().Detail("");

                return;
            }

            //logItem.LogHeaderId = ???
            logItem.TimeStampUtc = DateTime.UtcNow;

            _logger.Write(logItem);

            //_logger.Writer<IAcConsoleLogWriter>()?.Write(logItem.AppType, logItem.LogLevel, logItem.Text, logItem.CallerName, logItem.CategoryName, logItem.ErrorType, logItem.Exception);
            //_logger.Writer<DbLogItemWriter>().WriteLogItemAsync(logItem);
        }
        catch (Exception ex)
        {
            Console.WriteLine($@"ERROR!!! {nameof(AcLoggerSignalRHub<TLogger>)}->AddLogItem; ex: {ex.Message}{AcEnv.NL}{AcEnv.NL}{ex}");
        }
    }
}