using Microsoft.AspNetCore.SignalR;
using PlotLine.Hubs;
using PlotLine.Models;

namespace PlotLine.Services;

public interface IStoryIntelligenceProgressNotifier
{
    Task PublishAsync(StoryIntelligenceRunProgressEvent progress);
}

public sealed class StoryIntelligenceProgressNotifier(IHubContext<StoryIntelligenceHub> hub) : IStoryIntelligenceProgressNotifier
{
    public Task PublishAsync(StoryIntelligenceRunProgressEvent progress)
        => hub.Clients.Group(StoryIntelligenceHub.UserGroup(progress.UserID))
            .SendAsync("StoryIntelligenceRunProgressChanged", progress);
}
