class PostmanScenarioIndexerService {

    List<Scenario> collectItemScenarios(ItemWithScripts[] items, Source source, AtomicInteger requestPosition, String parentSeverity, List<Assertion> parentAssertions, String... parentFolders) {
        List<Scenario> scenarios = new ArrayList<>();
        if (items != null) {
            for (ItemWithScripts item : items) {
                boolean isRootFolder = (parentFolders.length == 0);
                boolean isFolder = isRootFolder || item.isSubFolder();

                // Compute item severity (deepest items' severity override severity of previous ones)
                String severity = postmanService.getSeverity(ArrayUtils.addAll(parentFolders, item.getName()));
                if (StringUtils.isEmpty(severity)) {
                    severity = parentSeverity;
                }

                // Compute item path (without any tag)
                String nameWithoutTag = postmanService.removeSeverityTag(item.getName());
                String[] path = ArrayUtils.addAll(parentFolders, nameWithoutTag);

                // Compute assertions of item (deepest items' assertions come first)
                List<Assertion> assertions = ListUtils.union(extractAssertions(item), parentAssertions);

                if (isFolder) {
                    // Add the folder's children
                    scenarios.addAll(collectItemScenarios(item.getChildren(), source, requestPosition, severity, assertions, path));
                } else {
                    // Add the request
                    scenarios.add(toScenario(item, source, requestPosition, severity, assertions, path));
                }
            }
        }
        return scenarios;
    }

}