using Microsoft.EntityFrameworkCore;
using NetinaShop.Domain.Entities.Accounting;

namespace NetinaShop.Repository.Handlers.Accounting;

public class GetPaymentsQueryHandler : IRequestHandler<GetPaymentsQuery,List<PaymentSDto>>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetPaymentsQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<List<PaymentSDto>> Handle(GetPaymentsQuery request, CancellationToken cancellationToken)
    {
        return await _repositoryWrapper.SetRepository<Payment>()
            .TableNoTracking
            .Skip(20 * request.Page)
            .Take(20)
            .Select(PaymentMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);
    }
}