using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;

using Serilog;

namespace Monitoring.Notifications;

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public sealed class NotificationHub : Hub
{
	public override async Task OnConnectedAsync()
	{
		Log.Information("NotificationHub - OnConnectedAsync - {UserIdentifier}", Context.UserIdentifier);

		await Clients.Caller.SendAsync("Connected");

		await base.OnConnectedAsync();
	}

	public override Task OnDisconnectedAsync(Exception? exception)
	{
		Log.Information("NotificationHub - OnDisconnectedAsync - {UserIdentifier}", Context.UserIdentifier);

		return base.OnDisconnectedAsync(exception);
	}
}
