using Baya.Application.Contracts.Common;
using Baya.Application.Contracts.Notifications;
using Baya.Application.Models.Common;
using Mediator;

namespace Baya.Application.Features.Notifications.Commands.MarkAllRead;

internal sealed class MarkAllReadCommandHandler(INotificationService notifications, ICurrentUser currentUser)
    : IRequestHandler<MarkAllReadCommand, OperationResult<bool>>
{
    public async ValueTask<OperationResult<bool>> Handle(MarkAllReadCommand request, CancellationToken cancellationToken)
    {
        if (currentUser.UserId is not { } userId)
            return OperationResult<bool>.FailureResult("User", "Not authenticated.");

        await notifications.MarkAllReadAsync(userId, cancellationToken);
        return OperationResult<bool>.SuccessResult(true);
    }
}
