"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const R = require("ramda");
const Auth_1 = require("../modules/Auth");
const I18n_1 = require("../modules/I18n");
const Logger_1 = require("../modules/Logger");
logout();
function logout() {
    return __awaiter(this, void 0, void 0, function* () {
        const auth = new Auth_1.default();
        const isLogenIn = yield auth.isTokenActive();
        return R.ifElse(R.not, logNotLogged, () => doLogout(auth))(isLogenIn);
    });
}
function doLogout(auth) {
    return auth.logout()
        .then(logSuccess)
        .catch(handleError);
}
function handleError(err) {
    if (err.code === 'NOT_LOGGED_IN') {
        return logNotLogged();
    }
    logError();
}
function logNotLogged() {
    Logger_1.default.info(I18n_1.default.info('NOT_LOGGED_IN_YET'));
}
function logSuccess() {
    Logger_1.default.info(I18n_1.default.info('LOGOUT_OK'));
}
function logError() {
    Logger_1.default.error(I18n_1.default.error('LOGOUT_ERR'));
}
//# sourceMappingURL=wiz-logout.js.map