"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _config = _interopRequireDefault(require("../../config"));

var _core = require("../../core");

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

var _runLogger = _interopRequireDefault(require("./run-logger"));

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 _default =
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
  var _ref2,
      _ref2$selectedSeeders,
      selectedSeeders,
      _ref2$dropDatabase,
      dropDatabase,
      _config$loadUserConfi,
      connect,
      dropdb,
      seedersList,
      logger,
      runner,
      observable,
      _args = arguments;

  return regeneratorRuntime.wrap(function _callee$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          _ref2 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref2$selectedSeeders = _ref2.selectedSeeders, selectedSeeders = _ref2$selectedSeeders === void 0 ? [] : _ref2$selectedSeeders, _ref2$dropDatabase = _ref2.dropDatabase, dropDatabase = _ref2$dropDatabase === void 0 ? false : _ref2$dropDatabase;
          (0, _helpers.validateUserConfig)(); // get relevant user-config

          _config$loadUserConfi = _config["default"].loadUserConfig(), connect = _config$loadUserConfi.connect, dropdb = _config$loadUserConfi.dropdb, seedersList = _config$loadUserConfi.seedersList; // create logger

          logger = new _runLogger["default"](); // create runner

          runner = new _core.MdSeedRunner({
            connect: connect,
            dropdb: dropdb,
            seedersList: seedersList
          }); // run seeders

          observable = runner.run({
            selectedSeeders: selectedSeeders,
            dropDatabase: dropDatabase
          }); // subscribe logger

          observable.subscribe(logger.asObserver()); // wait for runner

          _context.next = 9;
          return observable.toPromise();

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

exports["default"] = _default;