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

        await notificationService.NotifyTaskDeleted(
            notification.TenantId.Value,
            notification.ProjectId.Value,
            notification.StoryId.Value,
            notification.TaskId.Value);

        logger.LogInformation("SignalR notification sent for task {TaskId}", notification.TaskId);
    }
}
