namespace Brizco.Repository.Handlers.Shift;

public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<ShiftSDto>>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetShiftPlansQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<List<ShiftSDto>> Handle(GetShiftsQuery request, CancellationToken cancellationToken)
    {
        var shifts = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>().TableNoTracking
            .OrderByDescending(s => s.CreatedAt)
            .Skip(request.page * 15).Take(15)
            .Select(ShiftMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);


        return shifts;
    }
}