private function injectRepositoryCredentials(
        Definition $definition,
        string $appName,
        array $repositoryConfiguration,
        string $indexName
    ) {
        if ($repositoryConfiguration['app_id']) {
            $repositoryReferenceName = rtrim("apisearch.repository_reference.$appName.$indexName", '.');
            $tokenUUIDName = rtrim("apisearch.token_uuid.$appName");
            $repositoryReferenceReference = new Reference($repositoryReferenceName);

            $repositoryConfiguration['token']
                ? $definition->addMethodCall('setCredentials', [
                    $repositoryReferenceReference,
                    new Reference($tokenUUIDName),
                ])
                : $definition->addMethodCall('setRepositoryReference', [
                    $repositoryReferenceReference,
                ]);
        }
    }