private function prepareSegment(string $name, string $segment): string
    {
        if (!empty($segment)) {
            return $this->filterSegment($segment);
        }

        if (!isset($this->constrains[$name])) {
            return self::DEFAULT_SEGMENT;
        }

        if (is_array($this->constrains[$name])) {
            $values = array_map([$this, 'filterSegment'], $this->constrains[$name]);

            return join('|', $values);
        }

        return $this->filterSegment((string)$this->constrains[$name]);
    }