using Microsoft.AspNetCore.SignalR;
using SolutionErp.Application.Common.Interfaces;

namespace SolutionErp.Api.Hubs;

public class SignalRNotifier(IHubContext<NotificationHub> hub) : IRealtimeNotifier
{
    public async Task PushToUserAsync(Guid userId, string eventName, object payload, CancellationToken ct = default)
    {
        // Clients.User(userId) uses default IUserIdProvider → reads
        // ClaimTypes.NameIdentifier. Our JWT places the user id in "sub"
        // which ASP.NET maps to NameIdentifier, so this resolves correctly.
        await hub.Clients.User(userId.ToString()).SendAsync(eventName, payload, ct);
    }
}
