"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = downloadModules;

var _ = require(".");

var _utils = require("../../utils");

/**
 * Loop through Nanodegree's modules and call @function downloadLessons
 * @param {object} modules parts JSON data from Nanodegree JSON
 * @param {string} ndKey Nanodegree key
 * @param {string} dirPart Nanodegree part's path
 * @param {string} udacityAuthToken Udacity authentication token
 */
async function downloadModules(modules, ndKey, dirPart, udacityAuthToken) {
  for (let i = 0, len = modules.length; i < len; i += 1) {
    const module = modules[i];
    const numberingModule = i + 1 < 10 ? `0${i + 1}` : i + 1;
    const dirModuleName = (0, _utils.filenamify)(`Module ${numberingModule}_${module.title}`);
    const dirModule = (0, _utils.makeDir)(dirPart, dirModuleName);
    await (0, _.downloadLessons)(module.lessons, ndKey, dirModule, udacityAuthToken);
  }

  return null;
}