'use strict';

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

var _regenerator;

function _load_regenerator() {
  return _regenerator = _interopRequireDefault(require('babel-runtime/regenerator'));
}

var _consumer;

function _load_consumer() {
  return _consumer = require('../../../consumer');
}

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

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee() {
    var absPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : process.cwd();
    var noGit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
    var reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    var resetHard = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
    var overrideBitJson, consumer;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            overrideBitJson = false;

            if (!(reset || resetHard)) {
              _context.next = 5;
              break;
            }

            _context.next = 4;
            return (_consumer || _load_consumer()).Consumer.reset(absPath, resetHard, noGit);

          case 4:
            overrideBitJson = true;

          case 5:
            _context.next = 7;
            return (_consumer || _load_consumer()).Consumer.create(absPath, noGit);

          case 7:
            consumer = _context.sent;
            return _context.abrupt('return', consumer.write({ overrideBitJson }));

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

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

  return init;
}();