namespace DocuMed.Repository.Handlers.Hospitals;

public class GetHospitalsQueryHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler<GetHospitalsQuery, List<HospitalSDto>>
{
    public async Task<List<HospitalSDto>> Handle(GetHospitalsQuery request, CancellationToken cancellationToken)
    {
        var response = await repositoryWrapper.SetRepository<Hospital>()
            .TableNoTracking
            .Skip(request.Page * request.Size)
            .Take(request.Size)
            .Select(HospitalMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);

        return response;
    }
}