using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using RobotNet.ScriptManager.Services;
using RobotNet.Shares;

namespace RobotNet.ScriptManager.Hubs;

[Authorize]
public class ScriptTaskHub(ScriptTaskManager taskManager) : Hub
{
    public MessageResult Pause(string name)
    {
        if (taskManager.Pause(name))
        {
            return new MessageResult(true, $"Task '{name}' paused successfully.");
        }
        return new MessageResult(false, $"Task '{name}' not found or could not be paused.");
    }

    public MessageResult Resume(string name)
    {
        if (taskManager.Resume(name))
        {
            return new MessageResult(true, $"Task '{name}' resumed successfully.");
        }
        return new MessageResult(false, $"Task '{name}' not found or could not be resumed.");
    }

    public IDictionary<string, bool> GetTaskStates()
    {
        return taskManager.GetTaskStates();
    }
}
