'use strict';

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

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

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

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

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

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

require('source-map-support/register');

var _requireDir = require('require-dir');

var _requireDir2 = _interopRequireDefault(_requireDir);

var _Plugin2 = require('./Plugin');

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

var json = require('format-json');

/**
 * Create an Executor to run Builds, Deploys, and Tests
 */

var Executor = exports.Executor = function (_Plugin) {
    (0, _inherits3.default)(Executor, _Plugin);

    /**
     * Initialise the CI Executor
     * @param {String} executorType - Class Name to Create
     * @param {*} eventData - Object of Options to pass into Class
     * @param {Logger} log - child logger for event
     */
    function Executor(eventData, log) {
        (0, _classCallCheck3.default)(this, Executor);

        var _this = (0, _possibleConstructorReturn3.default)(this, (Executor.__proto__ || (0, _getPrototypeOf2.default)(Executor)).call(this));

        _this.log = log;

        _this.eventId = eventData.ghEventId;
        _this.eventType = eventData.ghEventType;
        _this.taskConfig = eventData.ghTaskConfig;
        _this.eventData = eventData;

        _this.log.info('----------------------------');
        _this.log.info('New Executor Created');
        _this.log.info('Event ID: ' + _this.eventId);
        _this.log.info('Event Type: ' + _this.eventType);
        _this.log.info('----------------------------');
        _this.log.debug('Task Config: ' + json.plain(_this.taskConfig));
        _this.log.debug(eventData);
        return _this;
    }

    /**
     * default implementation just returns env vars
     * @returns options specific to executor type
     */


    (0, _createClass3.default)(Executor, [{
        key: 'getOptions',
        value: function getOptions() {
            return process.env;
        }
    }, {
        key: 'executeTask',
        value: function () {
            var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
                return _regenerator2.default.wrap(function _callee$(_context) {
                    while (1) {
                        switch (_context.prev = _context.next) {
                            case 0:
                            case 'end':
                                return _context.stop();
                        }
                    }
                }, _callee, this);
            }));

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

            return executeTask;
        }()
    }]);
    return Executor;
}(_Plugin2.Plugin);

(0, _requireDir2.default)('../executors');