namespace EEMSServerCore.Hubs;

internal class UIHub(DeviceManager deviceManager) : Hub, IUICaller
{
    public override Task OnConnectedAsync()
    {
        ClientManager.UIClient = Clients.All;
        return base.OnConnectedAsync();
    }

    public Task<bool> RemoveDevice(Guid guid)
    {
        deviceManager.RemoveDevice(guid, out _);
        return Task.FromResult(true);
    }

    public Task<IEnumerable<DeviceInfo>> RequestDeviceLists()
    {
        if (!deviceManager.GetDeviceList(out Dictionary<Guid, DeviceInfo>? devices) || devices is null)
            return Task.FromResult(Enumerable.Empty<DeviceInfo>());

        IEnumerable<DeviceInfo> results = devices.Values;

        return Task.FromResult(results);

    }

    public Task<bool> UpdateDeviceInfo(DeviceInfo deviceInfo)
    {
        return Task.FromResult(true);
    }
}