* > */ final readonly class GetFoCustomerPaginatedOrdersQuery implements Query { /** * @param \App\Queries\Orders\GetFoCustomerPaginatedOrdersQueryInput $input * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ #[\Override] public function __invoke(QueryInput $input): LengthAwarePaginator { Assert::isInstanceOf($input, GetFoCustomerPaginatedOrdersQueryInput::class); /** @var \Domain\Models\ValueObjects\Matricule|null $employeeMatricule */ $employeeMatricule = $input->customer->employee()->value('matricule'); if ($employeeMatricule === null) { return new ConcreteLengthAwarePaginator( items: [], total: 0, perPage: $input->pagination->pageSize()->value(), currentPage: $input->pagination->pageNumber()->value(), ); } $paginator = Order::query() ->where('employee_matricule', $employeeMatricule->value) ->orderBy('id', SortDirection::Descending) ->paginate( perPage: $input->pagination->pageSize()->value(), page: $input->pagination->pageNumber()->value(), ); return $paginator->through(fn (Order $order): OrderDto => OrderDto::fromModel($order)); } }