public function create(\Psr\Http\Message\ServerRequestInterface $request, string $sortParameter = self::SORT, array $defaultSort = []): Pagination
    {
        $offset = 0;
        $max = PHP_INT_MAX;
        
        $params = $request->getQueryParams();
        $range = $request->getHeaderLine(self::RANGE);
        
        if ($range !== null && preg_match(self::REGEX_RANGE, $range, $rm)) {
            // dojo.store.JsonRest style
            $offset = (int)$rm[1];
            $max = (int)$rm[2] - $offset + 1;
        } else {
            $max = $this->parse(self::$maxAlias, $params, PHP_INT_MAX);
            // Grails, ExtJS, dojox.data.QueryReadStore, all zero-based
            $offVal = $this->parse(self::$offsetAlias, $params, 0);
            if ($offVal > 0) {
                $offset = $offVal;
            } elseif (isset($params[self::START_INDEX])) {
            // OpenSearch style, 1-based
                $startIdx = isset($params[self::START_INDEX]) ? (int)$params[self::START_INDEX] : 0;
                if ($startIdx > 0) {
                    $offset = $startIdx - 1;
                }
            } elseif (isset($params[self::START_PAGE]) || isset($params[self::PAGE])) {
            // OpenSearch or Spring Data style, 1-based
                $startPage = $this->parse(self::$pageAlias, $params, 0);
                if ($startPage > 0) {
                    $offset = ($max * ($startPage - 1));
                }
            }
        }
        
        return new Pagination($max, $offset, $this->getOrder($request, $sortParameter, $defaultSort));
    }