'use strict';
'use warning';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _lodash = _interopRequireDefault(require("lodash"));

var _mongodb = require("mongodb");

var MongoDB =
/**
 *
 * @param {JSON} config
 * @param {String} config.host
 * @param {String} config.port
 * @param {String} config.database
 * @returns {Promise}
 */
function MongoDB(config) {
  var _this = this;

  (0, _classCallCheck2["default"])(this, MongoDB);
  (0, _defineProperty2["default"])(this, "CreateUser", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  this.config = _lodash["default"].extend({
    host: "localhost",
    port: 27017,
    database: undefined
  }, config);
  this.host = "\"mongodb://".concat(this.config.host, ":").concat(this.config.port, "/\"");
  return new Promise( /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(resolve, rejected) {
      return _regenerator["default"].wrap(function _callee3$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              _mongodb.MongoClient.connect(_this.host, /*#__PURE__*/function () {
                var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(err, MongoClient) {
                  var MongoDbInstance;
                  return _regenerator["default"].wrap(function _callee2$(_context2) {
                    while (1) {
                      switch (_context2.prev = _context2.next) {
                        case 0:
                          if (!err) {
                            _this.MongoClient = MongoClient;
                            MongoDbInstance = _this.config.database !== undefined ? MongoClient.db(_this.config.database) : MongoClient;
                            resolve(MongoClient);
                          } else {
                            rejected(err.code);
                          }

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

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

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

    return function (_x, _x2) {
      return _ref2.apply(this, arguments);
    };
  }());
};

var _default = MongoDB;
exports["default"] = _default;
//# sourceMappingURL=index.js.map