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

namespace RobotNet.ScriptManager.Hubs;

[Authorize]
public class DashboardHub(DashboardPublisher DashboardPublisher, ILogger<DashboardHub> Logger) : Hub
{
    public MessageResult<DashboardDto> GetDashboardData()
    {
        try
        {
            return new(true, "") { Data = DashboardPublisher.GetData() };
        }
        catch (Exception ex)
        {
            Logger.LogWarning("Lấy dữ liệu Dashboard xảy ra lỗi: {ex}", ex.Message);
            return new(false, "Lấy dữ liệu Dashboard xảy ra lỗi");
        }
    }
}
