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

namespace ColaFlow.Modules.IssueManagement.Application.EventHandlers;

public sealed class IssueStatusChangedEventHandler : INotificationHandler<IssueStatusChangedEvent>
{
    private readonly ILogger<IssueStatusChangedEventHandler> _logger;

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

    public Task Handle(IssueStatusChangedEvent notification, CancellationToken cancellationToken)
    {
        _logger.LogInformation(
            "Issue status changed: {IssueId} from {OldStatus} to {NewStatus}",
            notification.IssueId,
            notification.OldStatus,
            notification.NewStatus);

        // SignalR notification will be handled by IRealtimeNotificationService

        return Task.CompletedTask;
    }
}
