const async = require('async');
const Page = require('../models/Page');

module.exports = (section, meta, callback) => {

  // Create a page for the top level page
  var sectionObj = new Page(section, meta);

  // Add any child pages
  if (section.subSections) {    
    sectionObj.children = [];

    section.subSections.forEach((subSection) => {
      sectionObj.children.push(new Page(subSection, meta, sectionObj.key));
    });
  }

  callback(null, sectionObj);
}