using NetinaShop.Domain.Entities.Orders;

namespace NetinaShop.Repository.Handlers.Orders;

public class GetOrdersQueryHandler : IRequestHandler<GetOrdersQuery,List<OrderSDto>>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetOrdersQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public Task<List<OrderSDto>> Handle(GetOrdersQuery request, CancellationToken cancellationToken)
    {
        return _repositoryWrapper.SetRepository<Order>()
            .TableNoTracking
            .Skip(request.Page * 15)
            .Take(15)
            .Select(OrderMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);

    }
}