"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.promptMissingOptions = exports.getOptions = void 0;

var _commandLineArgs2 = _interopRequireDefault(require("command-line-args"));

var _helpers = require("../../utils/helpers");

var _prompts = require("./prompts");

var _optionDefinitions = _interopRequireDefault(require("./option-definitions"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var getOptions = function getOptions(argv) {
  var _commandLineArgs = (0, _commandLineArgs2["default"])(_optionDefinitions["default"], {
    argv: argv
  }),
      seedersFolder = _commandLineArgs.seedersFolder,
      customSeederTemplate = _commandLineArgs.seederTemplate,
      helpWanted = _commandLineArgs.help;

  return {
    seedersFolder: seedersFolder,
    customSeederTemplate: customSeederTemplate,
    helpWanted: helpWanted
  };
};

exports.getOptions = getOptions;

var promptMissingOptions =
/*#__PURE__*/
function () {
  var _ref = _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee3() {
    var _ref2,
        seedersFolder,
        customSeederTemplate,
        getSeedersFolder,
        getCustomSeederTemplate,
        _args3 = arguments;

    return regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            _ref2 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, seedersFolder = _ref2.seedersFolder, customSeederTemplate = _ref2.customSeederTemplate;

            getSeedersFolder =
            /*#__PURE__*/
            function () {
              var _ref3 = _asyncToGenerator(
              /*#__PURE__*/
              regeneratorRuntime.mark(function _callee() {
                return regeneratorRuntime.wrap(function _callee$(_context) {
                  while (1) {
                    switch (_context.prev = _context.next) {
                      case 0:
                        if (!(0, _helpers.validateSeedersFolderName)(seedersFolder)) {
                          _context.next = 4;
                          break;
                        }

                        _context.t0 = seedersFolder;
                        _context.next = 7;
                        break;

                      case 4:
                        _context.next = 6;
                        return (0, _prompts.promptSeedersFolder)();

                      case 6:
                        _context.t0 = _context.sent;

                      case 7:
                        return _context.abrupt("return", _context.t0);

                      case 8:
                      case "end":
                        return _context.stop();
                    }
                  }
                }, _callee);
              }));

              return function getSeedersFolder() {
                return _ref3.apply(this, arguments);
              };
            }();

            getCustomSeederTemplate =
            /*#__PURE__*/
            function () {
              var _ref4 = _asyncToGenerator(
              /*#__PURE__*/
              regeneratorRuntime.mark(function _callee2() {
                return regeneratorRuntime.wrap(function _callee2$(_context2) {
                  while (1) {
                    switch (_context2.prev = _context2.next) {
                      case 0:
                        if (!(0, _helpers.validateSeederTemplatePath)(customSeederTemplate)) {
                          _context2.next = 4;
                          break;
                        }

                        _context2.t0 = customSeederTemplate;
                        _context2.next = 7;
                        break;

                      case 4:
                        _context2.next = 6;
                        return (0, _prompts.promptSeederTemplate)();

                      case 6:
                        _context2.t0 = _context2.sent;

                      case 7:
                        return _context2.abrupt("return", _context2.t0);

                      case 8:
                      case "end":
                        return _context2.stop();
                    }
                  }
                }, _callee2);
              }));

              return function getCustomSeederTemplate() {
                return _ref4.apply(this, arguments);
              };
            }();

            _context3.next = 5;
            return getSeedersFolder();

          case 5:
            _context3.t0 = _context3.sent;
            _context3.next = 8;
            return getCustomSeederTemplate();

          case 8:
            _context3.t1 = _context3.sent;
            return _context3.abrupt("return", {
              seedersFolder: _context3.t0,
              customSeederTemplate: _context3.t1
            });

          case 10:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));

  return function promptMissingOptions() {
    return _ref.apply(this, arguments);
  };
}();

exports.promptMissingOptions = promptMissingOptions;