class PipelineCodeHandler {

    @SuppressWarnings("PMD.AvoidCatchingGenericException")
    public List<DocWriteRequest> createPipelineCodeDocuments(final Pipeline pipeline,
                                                             final PermissionsContainer permissions,
                                                             final String revisionName,
                                                             final String indexName,
                                                             final List<String> pipelineFileIndexPaths) {
        return pipelineFileIndexPaths.stream()
                .map(path -> {
                    log.debug("Fetching path {} for revisionName {}", path, revisionName);
                    if (path.endsWith(FOLDER_INDICATOR)) {
                        return getGitRepositoryEntries(pipeline, revisionName, path)
                                .stream()
                                .filter(content -> (content.getType().equals(GIT_ENTRY_TYPE)))
                                .map(content ->
                                        createIndexRequest(
                                                pipeline, revisionName, indexName, content.getPath(), permissions))
                                .collect(Collectors.toList());
                    }
                    return Collections.singletonList(createIndexRequest(
                            pipeline, revisionName, indexName, path, permissions));
                })
                .flatMap(Collection::stream)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }

    public  PipelineCodeHandler(final @Value("${sync.index.common.prefix}") String indexPrefix,
                               final @Value("${sync.pipeline-code.index.name}") String pipelineCodeIndexName,
                               final CloudPipelineAPIClient cloudPipelineAPIClient,
                               final ElasticIndexService indexService,
                               final @Value("${sync.pipeline-code.index.paths}") String pipelineFileIndexPaths,
                               final ObjectMapper objectMapper,
                               final PipelineLoader pipelineLoader,
                               final PipelineCodeMapper codeMapper,
                               final @Value("${sync.pipeline-code.default-branch}") String defaultBranchName,
                               final @Value("${sync.pipeline-code.max.bytes:10240}") Integer codeLimitBytes);

}