'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _util = require('util');

var _util2 = _interopRequireDefault(_util);

var _parameter_type_registry_builder = require('./parameter_type_registry_builder');

var _parameter_type_registry_builder2 = _interopRequireDefault(_parameter_type_registry_builder);

var _define_helpers = require('./define_helpers');

var _finalize_helpers = require('./finalize_helpers');

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

var SupportCodeLibraryBuilder = exports.SupportCodeLibraryBuilder = function () {
  function SupportCodeLibraryBuilder() {
    var _this = this;

    (0, _classCallCheck3.default)(this, SupportCodeLibraryBuilder);

    this.methods = {
      defineParameterType: (0, _define_helpers.defineParameterType)(this),
      After: (0, _define_helpers.defineTestCaseHook)(this, 'afterTestCaseHookDefinitions'),
      AfterAll: (0, _define_helpers.defineTestRunHook)(this, 'afterTestRunHookDefinitions'),
      Before: (0, _define_helpers.defineTestCaseHook)(this, 'beforeTestCaseHookDefinitions'),
      BeforeAll: (0, _define_helpers.defineTestRunHook)(this, 'beforeTestRunHookDefinitions'),
      defineStep: (0, _define_helpers.defineStep)(this),
      defineSupportCode: _util2.default.deprecate(function (fn) {
        fn(_this.methods);
      }, 'cucumber: defineSupportCode is deprecated. Please require/import the individual methods instead.'),
      setDefaultTimeout: function setDefaultTimeout(milliseconds) {
        _this.options.defaultTimeout = milliseconds;
      },
      setDefinitionFunctionWrapper: function setDefinitionFunctionWrapper(fn) {
        _this.options.definitionFunctionWrapper = fn;
      },
      setWorldConstructor: function setWorldConstructor(fn) {
        _this.options.World = fn;
      }
    };
    this.methods.Given = this.methods.When = this.methods.Then = this.methods.defineStep;
  }

  (0, _createClass3.default)(SupportCodeLibraryBuilder, [{
    key: 'finalize',
    value: function finalize() {
      var _this2 = this;

      (0, _finalize_helpers.wrapDefinitions)({
        cwd: this.cwd,
        definitionFunctionWrapper: this.options.definitionFunctionWrapper,
        definitions: _lodash2.default.chain(['afterTestCaseHook', 'afterTestRunHook', 'beforeTestCaseHook', 'beforeTestRunHook', 'step']).map(function (key) {
          return _this2.options[key + 'Definitions'];
        }).flatten().value()
      });
      this.options.afterTestCaseHookDefinitions.reverse();
      this.options.afterTestRunHookDefinitions.reverse();
      return this.options;
    }
  }, {
    key: 'reset',
    value: function reset(cwd) {
      this.cwd = cwd;
      this.options = _lodash2.default.cloneDeep({
        afterTestCaseHookDefinitions: [],
        afterTestRunHookDefinitions: [],
        beforeTestCaseHookDefinitions: [],
        beforeTestRunHookDefinitions: [],
        defaultTimeout: 5000,
        definitionFunctionWrapper: null,
        stepDefinitions: [],
        parameterTypeRegistry: _parameter_type_registry_builder2.default.build(),
        World: function World(_ref) {
          var attach = _ref.attach,
              parameters = _ref.parameters;

          this.attach = attach;
          this.parameters = parameters;
        }
      });
    }
  }]);
  return SupportCodeLibraryBuilder;
}();

exports.default = new SupportCodeLibraryBuilder();
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 6444 characters]