private function buildBlockTypeGroups(ContainerBuilder $container, array $blockTypeGroups, array $blockTypes): Generator
    {
        foreach ($blockTypeGroups as $identifier => $blockTypeGroup) {
            $serviceIdentifier = sprintf('netgen_block_manager.block.block_type_group.%s', $identifier);

            $blockTypeReferences = [];
            foreach ($blockTypeGroup['block_types'] as $blockTypeIdentifier) {
                if (isset($blockTypes[$blockTypeIdentifier])) {
                    $blockTypeReferences[] = new Reference(
                        sprintf(
                            'netgen_block_manager.block.block_type.%s',
                            $blockTypeIdentifier
                        )
                    );
                }
            }

            $container->register($serviceIdentifier, BlockTypeGroup::class)
                ->setArguments([$identifier, $blockTypeGroup, $blockTypeReferences])
                ->setLazy(true)
                ->setPublic(true)
                ->setFactory([BlockTypeGroupFactory::class, 'buildBlockTypeGroup']);

            yield $identifier => new Reference($serviceIdentifier);
        }
    }