using Netina.Domain.Entities.Accounting;

namespace Netina.Repository.Handlers.Accounting;

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