'use strict';

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

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

var _regenerator2 = _interopRequireDefault(_regenerator);

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

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

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

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

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

var _createClass3 = _interopRequireDefault(_createClass2);

var _LaunchDarklyApiClient = require('./LaunchDarklyApiClient');

var _LaunchDarklyLogger = require('./LaunchDarklyLogger');

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

var log = _LaunchDarklyLogger.LaunchDarklyLogger.logger();

var LaunchDarklyUtils = exports.LaunchDarklyUtils = function () {
    function LaunchDarklyUtils() {
        (0, _classCallCheck3.default)(this, LaunchDarklyUtils);
    }

    (0, _createClass3.default)(LaunchDarklyUtils, [{
        key: 'create',
        value: function () {
            var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(API_TOKEN, customLogger) {
                return _regenerator2.default.wrap(function _callee$(_context) {
                    while (1) {
                        switch (_context.prev = _context.next) {
                            case 0:
                                if (customLogger) log = customLogger;
                                _context.next = 3;
                                return _LaunchDarklyApiClient.LaunchDarklyApiClient.create(API_TOKEN, log);

                            case 3:
                                this.apiClient = _context.sent;
                                return _context.abrupt('return', this);

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

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

            return create;
        }()
    }, {
        key: 'getFeatureFlags',
        value: function () {
            var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(projectKey) {
                return _regenerator2.default.wrap(function _callee2$(_context2) {
                    while (1) {
                        switch (_context2.prev = _context2.next) {
                            case 0:
                                return _context2.abrupt('return', this.apiClient.apis.flags.getFeatureFlags({ projectKey: projectKey }));

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

            function getFeatureFlags(_x3) {
                return _ref2.apply(this, arguments);
            }

            return getFeatureFlags;
        }()
    }, {
        key: 'getFeatureFlag',
        value: function () {
            var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(projectKey, featureFlagKey, environmentKeyQuery) {
                return _regenerator2.default.wrap(function _callee3$(_context3) {
                    while (1) {
                        switch (_context3.prev = _context3.next) {
                            case 0:
                                return _context3.abrupt('return', this.apiClient.apis.flags.getFeatureFlag({
                                    projectKey: projectKey,
                                    featureFlagKey: featureFlagKey,
                                    environmentKeyQuery: environmentKeyQuery
                                }));

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

            function getFeatureFlag(_x4, _x5, _x6) {
                return _ref3.apply(this, arguments);
            }

            return getFeatureFlag;
        }()
    }]);
    return LaunchDarklyUtils;
}();