using MediatR;
using Microsoft.Extensions.Logging;
using ColaFlow.Modules.ProjectManagement.Domain.Events;
using ColaFlow.Modules.ProjectManagement.Application.Services;

namespace ColaFlow.Modules.ProjectManagement.Application.EventHandlers;

/// <summary>
/// Handler for StoryDeletedEvent - sends SignalR notification
/// </summary>
public class StoryDeletedEventHandler(
    IProjectNotificationService notificationService,
    ILogger<StoryDeletedEventHandler> logger)
    : INotificationHandler<StoryDeletedEvent>
{
    public async Task Handle(StoryDeletedEvent notification, CancellationToken cancellationToken)
    {
        logger.LogInformation("Handling StoryDeletedEvent for story {StoryId}", notification.StoryId);

        await notificationService.NotifyStoryDeleted(
            notification.TenantId.Value,
            notification.ProjectId.Value,
            notification.EpicId.Value,
            notification.StoryId.Value);

        logger.LogInformation("SignalR notification sent for story {StoryId}", notification.StoryId);
    }
}
