using Knot.Shared.Kernel;
using Knot.Shared.Kernel.Events;
using Knot.Contracts.Profiles.Domain;
using Knot.Modules.Profiles.Domain;
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace Knot.Modules.Profiles.Application.Profiles.Integration;

internal sealed class UserStatusChangedHandler : 
    INotificationHandler<UserBannedDomainEvent>,
    INotificationHandler<UserDeletedDomainEvent>
{
    private readonly IProfileRepository _repository;

    public UserStatusChangedHandler(IProfileRepository repository)
    {
        _repository = repository;
    }

    public async Task Handle(UserBannedDomainEvent notification, CancellationToken cancellationToken)
    {
        await _repository.UpdateStatusAsync(notification.UserId, notification.IsBanned, false, cancellationToken);
    }

    public async Task Handle(UserDeletedDomainEvent notification, CancellationToken cancellationToken)
    {
        await _repository.DeleteAsync(notification.UserId, cancellationToken);
    }
}
