using Microsoft.AspNetCore.SignalR;
using RobotNet.ScriptManager.Hubs;

namespace RobotNet.ScriptManager.Models;

public class ConsoleLog(IHubContext<ConsoleHub> consoleHub, ILogger? logger = null) : Script.ILogger
{
    public void LogError(string message)
    {
        _ = Task.Factory.StartNew(Task () => consoleHub.Clients.All.SendAsync("MessageError", message));
        logger?.LogError(message);
    }

    public void LogInfo(string message)
    {
        _ = Task.Factory.StartNew(Task () => consoleHub.Clients.All.SendAsync("MessageInfo", message));
        logger?.LogInformation(message);
    }

    public void LogWarning(string message)
    {
        _ = Task.Factory.StartNew(Task () => consoleHub.Clients.All.SendAsync("MessageWarning", message));
        logger?.LogWarning(message);
    }
}
