private IEnumerable? ReadChild()

in src/Elastic.Documentation.Configuration/Builder/TableOfContentsConfiguration.cs [129:211]


	private IEnumerable<ITocItem>? ReadChild(YamlStreamReader reader, YamlMappingNode tocEntry, string parentPath)
	{
		string? file = null;
		string? folder = null;
		string[]? detectionRules = null;
		TableOfContentsConfiguration? toc = null;
		var detectionRulesFound = false;
		var hiddenFile = false;
		IReadOnlyCollection<ITocItem>? children = null;
		foreach (var entry in tocEntry.Children)
		{
			var key = ((YamlScalarNode)entry.Key).Value;
			switch (key)
			{
				case "toc":
					toc = ReadNestedToc(reader, entry, parentPath);
					break;
				case "hidden":
				case "file":
					hiddenFile = key == "hidden";
					file = ReadFile(reader, entry, parentPath);
					break;
				case "folder":
					folder = ReadFolder(reader, entry, parentPath);
					parentPath += $"{Path.DirectorySeparatorChar}{folder}";
					break;
				case "detection_rules":
					if (_configuration.Extensions.IsDetectionRulesEnabled)
					{
						detectionRules = ReadDetectionRules(reader, entry, parentPath, out detectionRulesFound);
						parentPath += $"{Path.DirectorySeparatorChar}{folder}";
					}
					break;
				case "children":
					children = ReadChildren(reader, entry, parentPath);
					break;
			}
		}

		if (toc is not null)
		{
			foreach (var f in toc.Files)
				_ = Files.Add(f);

			return [new TocReference(toc.Source, toc, $"{parentPath}".TrimStart(Path.DirectorySeparatorChar), toc.TableOfContents)];
		}

		if (file is not null)
		{
			if (detectionRules is not null)
			{
				if (children is not null)
					reader.EmitError($"'detection_rules' is not allowed to have 'children'", tocEntry);

				if (!detectionRulesFound)
				{
					reader.EmitError($"'detection_rules' folder {parentPath} is not found, skipping'", tocEntry);
					children = [];
				}
				else
				{
					var overviewPath = $"{parentPath}{Path.DirectorySeparatorChar}{file}".TrimStart(Path.DirectorySeparatorChar);
					var landingPage = new RuleOverviewReference(this, overviewPath, parentPath, _configuration, _context, detectionRules);
					foreach (var child in landingPage.Children.OfType<FileReference>())
						_ = Files.Add(child.RelativePath);
					return [landingPage];
				}
			}

			var path = $"{parentPath}{Path.DirectorySeparatorChar}{file}".TrimStart(Path.DirectorySeparatorChar);
			return [new FileReference(this, path, hiddenFile, children ?? [])];
		}

		if (folder is not null)
		{
			if (children is null)
				_ = _configuration.ImplicitFolders.Add(parentPath.TrimStart(Path.DirectorySeparatorChar));

			return [new FolderReference(this, $"{parentPath}".TrimStart(Path.DirectorySeparatorChar), children ?? [])];
		}

		return null;
	}