'use strict';

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

var _regenerator2 = _interopRequireDefault(_regenerator);

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

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _LaunchDarklyUtils = require('./src/LaunchDarklyUtils');

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

var _dotenv = require('dotenv');

var _dotenv2 = _interopRequireDefault(_dotenv);

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

_dotenv2.default.config();

var log = _LaunchDarklyLogger.LaunchDarklyLogger.logger();

var args = process.argv.slice(2);
log.info('command line args: ' + args);

(0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
    var ldUtils, mode, result, projectKey, featureFlagKey, environmentKeyQuery;
    return _regenerator2.default.wrap(function _callee$(_context) {
        while (1) {
            switch (_context.prev = _context.next) {
                case 0:
                    _context.next = 2;
                    return new _LaunchDarklyUtils.LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log);

                case 2:
                    ldUtils = _context.sent;
                    mode = args[0];
                    result = void 0;
                    projectKey = void 0, featureFlagKey = void 0, environmentKeyQuery = void 0;
                    _context.t0 = mode;
                    _context.next = _context.t0 === 'getFeatureFlags' ? 9 : _context.t0 === 'getFeatureFlag' ? 17 : 33;
                    break;

                case 9:
                    projectKey = args[1];

                    if (!(!projectKey || projectKey.trim() === '')) {
                        _context.next = 13;
                        break;
                    }

                    result = 'please supply a projectKey as second parameter';
                    return _context.abrupt('break', 34);

                case 13:
                    _context.next = 15;
                    return ldUtils.getFeatureFlags(projectKey);

                case 15:
                    result = _context.sent;
                    return _context.abrupt('break', 34);

                case 17:
                    projectKey = args[1];
                    featureFlagKey = args[2];
                    environmentKeyQuery = args[3];

                    if (!(!projectKey || projectKey.trim() === '')) {
                        _context.next = 23;
                        break;
                    }

                    result = 'please supply a projectKey as second parameter';
                    return _context.abrupt('break', 34);

                case 23:
                    if (!(!featureFlagKey || featureFlagKey.trim() === '')) {
                        _context.next = 26;
                        break;
                    }

                    result = 'please supply a featureFlagKey as third parameter';
                    return _context.abrupt('break', 34);

                case 26:
                    if (!(!environmentKeyQuery || environmentKeyQuery.trim() === '')) {
                        _context.next = 29;
                        break;
                    }

                    result = 'please supply a environmentKeyQuery as fourth parameter';
                    return _context.abrupt('break', 34);

                case 29:
                    _context.next = 31;
                    return ldUtils.getFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery);

                case 31:
                    result = _context.sent;
                    return _context.abrupt('break', 34);

                case 33:
                    result = 'please supply a mode parameter: getFeatureFlags, getFeatureFlag';

                case 34:

                    log.info(result);

                case 35:
                case 'end':
                    return _context.stop();
            }
        }
    }, _callee, undefined);
}))();