export function flattenGroupNodes(
  nodes: MasterModel.GroupNode[],
): MasterModel.GroupNode[] {
  const result: MasterModel.GroupNode[] = [];

  function traverse(node: MasterModel.GroupNode) {
    const { children, ...nodeWithoutChildren } = node;
    result.push(nodeWithoutChildren);

    if (children && children.length > 0) {
      children.forEach((child) => traverse(child));
    }
  }

  nodes.forEach((node) => traverse(node));

  return result;
}
