use alloc::vec::Vec;
use crate::query::{match_ast_group_d, pred_ast};
use crate::syntax::builders::switch_body::build_switch_body_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let switch_id = pred_ast(graph, n_id, None)
.first()
.copied()
.ok_or(SyntaxGraphError::UnexpectedAstShape)?;
let mut case_ids: Vec<NodeId> = match_ast_group_d(graph, switch_id, "expression_case", None);
case_ids.extend(match_ast_group_d(graph, switch_id, "default_case", None));
case_ids.extend(match_ast_group_d(graph, switch_id, "type_case", None));
build_switch_body_node(args, n_id, &case_ids, None).map(Some)
}