using ColaFlow.Modules.Identity.Domain.Aggregates.Users.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace ColaFlow.Modules.Identity.Application.EventHandlers;

public sealed class UserLoggedInEventHandler(ILogger<UserLoggedInEventHandler> logger)
    : INotificationHandler<UserLoggedInEvent>
{
    public Task Handle(UserLoggedInEvent notification, CancellationToken cancellationToken)
    {
        logger.LogInformation(
            "User {UserId} logged in to tenant {TenantId} from IP {IpAddress}",
            notification.UserId,
            notification.TenantId.Value,
            notification.IpAddress);

        // Future: Track login history
        // Future: Detect suspicious login patterns
        // Future: Update last login timestamp

        return Task.CompletedTask;
    }
}
