public static function getPreviousSchema(SchemaId $schemaId)
    {
        $id = $schemaId->toString();

        if (isset(self::$schemas[$id])) {
            $ids = array_keys(self::$schemas);
            sort($ids);

            if (0 < $key = array_search($id, $ids)) {
                --$key;
            }

            if ($ids[$key] !== $id) {
                /** @var SchemaDescriptor $prev */
                $prev = self::$schemas[$ids[$key]];

                if ($prev
                    && $prev->getId()->getCurieWithMajorRev() === $schemaId->getCurieWithMajorRev()
                    && $prev->getId()->getVersion()->compare($schemaId->getVersion()) === -1
                ) {
                    return $prev;
                }
            }
        }

        return null;
    }