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 EpicDeletedEvent - sends SignalR notification
/// </summary>
public class EpicDeletedEventHandler(
    IProjectNotificationService notificationService,
    ILogger<EpicDeletedEventHandler> logger)
    : INotificationHandler<EpicDeletedEvent>
{
    public async Task Handle(EpicDeletedEvent notification, CancellationToken cancellationToken)
    {
        logger.LogInformation("Handling EpicDeletedEvent for epic {EpicId}", notification.EpicId);

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

        logger.LogInformation("SignalR notification sent for epic {EpicId}", notification.EpicId);
    }
}
