namespace Brizco.Repository.Handlers.Complex;

public class GetComplexesQueryHandler : IRequestHandler<GetComplexesQuery, List<ComplexSDto>>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetComplexesQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<List<ComplexSDto>> Handle(GetComplexesQuery request, CancellationToken cancellationToken)
    {
        var tasks = await _repositoryWrapper.SetRepository<Domain.Entities.Complex.Complex>().TableNoTracking
            .OrderByDescending(s => s.CreatedAt)
            .Skip(request.Page * 15).Take(15)
            .Select(ComplexMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);

        return tasks;
    }
}