'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _Map2 = require('./Map');

var _Map3 = _interopRequireDefault(_Map2);

var _Match = require('./Match');

var _Match2 = _interopRequireDefault(_Match);

var _AsyncTask = require('../tasks/AsyncTask');

var _AsyncTask2 = _interopRequireDefault(_AsyncTask);

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

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

/**
 * Map for AsyncTask
 *
 * Maps the default ways to get a AsyncTask
 */
var AsyncMap = function (_Map) {
  _inherits(AsyncMap, _Map);

  function AsyncMap() {
    _classCallCheck(this, AsyncMap);

    return _possibleConstructorReturn(this, (AsyncMap.__proto__ || Object.getPrototypeOf(AsyncMap)).apply(this, arguments));
  }

  _createClass(AsyncMap, [{
    key: 'match',

    /**
     * Match argument with a specific TriggerMap
     *
     * @param {Function} run function to be called on run
     * @param {Function} complete function to be called on complete
     * @param {Function} recover function to be called on recover
     * @param {number} marker 0 marks a async task
     * @return {Match} match
     */
    value: function match() {
      for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }

      if (args.length === 4 && typeof args[0] === 'function' && typeof args[1] === 'function' && typeof args[2] === 'function' && args[3] === 0) {
        return new _Match2.default(new (Function.prototype.bind.apply(_AsyncTask2.default, [null].concat(_toConsumableArray(args.slice(0, -1)))))());
      } else if (args.length === 3 && typeof args[0] === 'function' && typeof args[1] === 'function' && args[2] === 0) {
        return new _Match2.default(new (Function.prototype.bind.apply(_AsyncTask2.default, [null].concat(_toConsumableArray(args.slice(0, -1)))))());
      } else if (args.length === 2 && typeof args[0] === 'function' && args[1] === 0) {
        return new _Match2.default(new (Function.prototype.bind.apply(_AsyncTask2.default, [null].concat(_toConsumableArray(args.slice(0, -1)))))());
      } else {
        return undefined;
      }
    }
  }]);

  return AsyncMap;
}(_Map3.default);

exports.default = AsyncMap;