using Review = Netina.Domain.Entities.Reviews.Review;

namespace Netina.Core.EntityServices.ReviewHandlers;

public class ConfirmReviewCommandHandler(IRepositoryWrapper repositoryWrapper)
    : IRequestHandler<ConfirmReviewCommand, Guid>
{
    public async Task<Guid> Handle(ConfirmReviewCommand request, CancellationToken cancellationToken)
    {
        var review = await repositoryWrapper.SetRepository<Review>().TableNoTracking
            .FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken);
        if (review == null)
            throw new AppException("Review not found", ApiResultStatusCode.NotFound);
        review.ConfirmReview();

        repositoryWrapper.SetRepository<Review>().Update(review);
        await repositoryWrapper.SaveChangesAsync(cancellationToken);
        return review.Id;
    }
}