using MediatR;
using Microsoft.Extensions.Logging;
using ColaFlow.Modules.IssueManagement.Domain.Events;

namespace ColaFlow.Modules.IssueManagement.Application.EventHandlers;

public sealed class IssueCreatedEventHandler : INotificationHandler<IssueCreatedEvent>
{
    private readonly ILogger<IssueCreatedEventHandler> _logger;

    public IssueCreatedEventHandler(ILogger<IssueCreatedEventHandler> logger)
    {
        _logger = logger;
    }

    public Task Handle(IssueCreatedEvent notification, CancellationToken cancellationToken)
    {
        _logger.LogInformation(
            "Issue created: {IssueId} - {Title} in Project {ProjectId}",
            notification.IssueId,
            notification.Title,
            notification.ProjectId);

        // SignalR notification will be handled by IRealtimeNotificationService
        // This is called from the command handler after persistence

        return Task.CompletedTask;
    }
}
