public static function buildSearchSortParameter(array $sorts)
    {
        if (empty($sorts)) {
            return '';
        }
        $sorting = [];
        foreach ($sorts as $sortField => $direction) {
            if (!self::validateFieldName((string) $sortField)) {
                throw new \LogicException(sprintf('Invalid field name "%s" for sorting field', $sortField));
            }
            if (!\in_array($direction, [true, 'desc', 'asc'], true)) {
                throw new \LogicException(sprintf('Wrong sorting direction "%s" for field "%s". Use either "desc", "asc"',
                    $direction, $sortField
                ));
            }

            // Only output the "desc" direction as "asc" is the default sorting
            $sorting[] = $sortField.('desc' === $direction ? ' '.$direction : '');
        }

        if (empty($sorting)) {
            return '';
        }

        return implode(',', $sorting);
    }