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

namespace RobotNet.ScriptManager.Models;

public class ScriptTaskLogger(IHubContext<ConsoleHub> consoleHub, string name) : Script.ILogger
{
    public void LogError(string message)
    {
        _ = Task.Factory.StartNew(Task () => consoleHub.Clients.Groups("alls", "tasks", $"task-{name}").SendAsync("MessageError", message));
    }

    public void LogInfo(string message)
    {
        _ = Task.Factory.StartNew(Task () => consoleHub.Clients.Groups("alls", "tasks", $"task-{name}").SendAsync("MessageInfo", message));
    }

    public void LogWarning(string message)
    {
        _ = Task.Factory.StartNew(Task () => consoleHub.Clients.Groups("alls", "tasks", $"task-{name}").SendAsync("MessageWarning", message));
    }
}
