"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("./express");
const logger_1 = require("./logger");
const metrics_1 = require("./metrics");
const global_1 = require("./global");
const settings_1 = require("./settings");
const utils_1 = require("./utils");
const mockObjects_1 = require("./mockObjects");
const cassandraMock_1 = require("./mocks/cassandraMock");
const redisMock_1 = require("./mocks/redisMock");
const elasticMock_1 = require("./mocks/elasticMock");
const statics_1 = require("./statics");
const promBundle = require("express-prom-bundle");
let fs = require("fs");
let redisSetting = {};
let defaultOptions = require("../options.json"); //Default settins anyting start from this
exports.setDefaultFileOptions = function (filename) {
    return settings_1.default.Instance.setFile(filename);
};
exports.setDefaultOptions = function (options = null) {
    if (options != null) {
        settings_1.default.Instance.set(options);
    }
};
exports.setEnvMap = function (envMap) {
    if (envMap != null) {
        settings_1.default.Instance.setEnvMap(envMap);
    }
};
exports.setEnvMapFile = function (filename) {
    if (filename != null) {
        settings_1.default.Instance.setEnvMapFile(filename);
    }
};
exports.setCustomSettings = function (settings, token = "global") {
    settings_1.default.Instance.setCustom(token, settings);
};
exports.getCustomSettings = function (token = "global") {
    return settings_1.default.Instance.getCustom(token);
};
exports.getSettings = function () {
    return settings_1.default.Instance;
};
exports.resetSettings = function () {
    settings_1.default.Instance.reset();
};
exports.resetDefaultOptions = function (options = null) {
    defaultOptions = require("../options.json");
    if (options != null) {
        defaultOptions = utils_1.default.deepExtend({}, defaultOptions, options);
    }
    settings_1.default.Instance.set(defaultOptions);
};
exports.setProjectStatus = function (status) {
    global_1.default.Instance.personalStatus = status;
};
exports.setProjectFunctionality = function (isFunctional) {
    global_1.default.Instance.personalIsFunctional = isFunctional;
};
exports.isFunctional = function () {
    return global_1.default.Instance.isFunctional();
};
exports.express = function (options = {}) {
    let swagger = options.swagger ? options.swagger : null;
    let morgan = options.morgan ? options.morgan : null;
    let zipkin = options.zipkin ? options.zipkin : null;
    settings_1.default.Instance.setSwagger("global", swagger);
    settings_1.default.Instance.setMorgan("global", morgan);
    settings_1.default.Instance.setZipkin("global", zipkin);
    return new express_1.default();
};
exports.express.mock = function (options = {}) {
    return mockObjects_1.default.makeWebServer(options);
};
//Crashreporter
exports.crashreporter = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Crashreporters.get();
    }
    else {
        return global_1.default.Instance.Crashreporters.get(token);
    }
};
//Configurate just global, by overide default setting with new settings
exports.crashreporter.configurate = function (options = {}) {
    settings_1.default.Instance.setCrashReporter("global", options);
    global_1.default.Instance.Crashreporters.delete();
};
exports.crashreporter.newInstance = function (options = {}, token = "") {
    settings_1.default.Instance.setCrashReporter(token, options);
    return global_1.default.Instance.Crashreporters.newInstance(token);
};
exports.crashreporter.deleteInstance = function (token) {
    global_1.default.Instance.Crashreporters.delete(token);
};
exports.crashreporter.reset = function () {
    global_1.default.Instance.Crashreporters.reset();
};
//Logger
exports.logger = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Loggers.get();
    }
    else {
        return global_1.default.Instance.Loggers.get(token);
    }
};
//Configurate just global, by overide default setting with new settings
exports.logger.configurate = function (options = {}) {
    settings_1.default.Instance.setLogger("global", options);
    global_1.default.Instance.Loggers.delete();
};
exports.logger.newInstance = function (options = {}, token = "") {
    settings_1.default.Instance.setLogger(token, options);
    return global_1.default.Instance.Loggers.newInstance(token);
};
exports.logger.deleteInstance = function (token) {
    global_1.default.Instance.Loggers.delete(token);
};
exports.logger.reset = function () {
    global_1.default.Instance.Loggers.reset();
};
//Redis
exports.redis = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Redis.get();
    }
    else {
        return global_1.default.Instance.Redis.get(token);
    }
};
//Configurate just global, by overide default setting with new settings
exports.redis.configurate = function (options = {}) {
    settings_1.default.Instance.setRedis("global", options);
    global_1.default.Instance.Redis.delete();
};
exports.redis.newInstance = function (options = {}, token = "") {
    settings_1.default.Instance.setRedis(token, options);
    return global_1.default.Instance.Redis.newInstance(token);
};
exports.redis.deleteInstance = function (token) {
    global_1.default.Instance.Redis.delete(token);
};
exports.redis.reset = function () {
    global_1.default.Instance.Redis.reset();
};
exports.redis.mock = function (options = {}, customLib) {
    return mockObjects_1.default.makeRedis(options, customLib);
};
//Cassandras
exports.cassandra = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Cassandras.get();
    }
    else {
        return global_1.default.Instance.Cassandras.get(token);
    }
};
//Configurate just global, by overide default setting with new settings
exports.cassandra.configurate = function (options = {}) {
    settings_1.default.Instance.setCassandra("global", options);
    global_1.default.Instance.Cassandras.delete();
};
exports.cassandra.newInstance = function (options = {}, token = "") {
    settings_1.default.Instance.setCassandra(token, options);
    return global_1.default.Instance.Cassandras.newInstance(token);
};
exports.cassandra.deleteInstance = function (token) {
    global_1.default.Instance.Cassandras.delete(token);
};
exports.cassandra.reset = function () {
    global_1.default.Instance.Cassandras.reset();
};
exports.cassandra.mock = function (options = {}, cassandraLibrary) {
    return mockObjects_1.default.makeCassandra(options, cassandraLibrary);
};
//Elastic
exports.elastic = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Elastics.get();
    }
    else {
        return global_1.default.Instance.Elastics.get(token);
    }
};
//Configurate just global, by overide default setting with new settings
exports.elastic.configurate = function (options = {}) {
    settings_1.default.Instance.setElastic("global", options);
    global_1.default.Instance.Elastics.delete();
};
exports.elastic.newInstance = function (options = {}, token = "") {
    settings_1.default.Instance.setElastic(token, options);
    return global_1.default.Instance.Elastics.newInstance(token);
};
exports.elastic.deleteInstance = function (token) {
    global_1.default.Instance.Elastics.delete(token);
};
exports.elastic.reset = function () {
    global_1.default.Instance.Elastics.reset();
};
exports.elastic.mock = function (options = {}, customLib) {
    return mockObjects_1.default.makeElastic(options, customLib);
};
//Mysql
exports.mysql = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Mysql.get();
    }
    else {
        return global_1.default.Instance.Mysql.get(token);
    }
};
//Configurate just global, by overide default setting with new settings
exports.mysql.configurate = function (options = {}) {
    settings_1.default.Instance.setMysql("global", options);
    global_1.default.Instance.Mysql.delete();
};
exports.mysql.newInstance = function (options = {}, token = "") {
    settings_1.default.Instance.setMysql(token, options);
    return global_1.default.Instance.Mysql.newInstance(token);
};
exports.mysql.deleteInstance = function (token) {
    global_1.default.Instance.Mysql.delete(token);
};
exports.mysql.reset = function () {
    global_1.default.Instance.Mysql.reset();
};
//Mailer
exports.mailer = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Mailers.get();
    }
    else {
        return global_1.default.Instance.Mailers.get(token);
    }
};
//Configurate just global, by overide default setting with new settings
exports.mailer.configurate = function (options = {}) {
    settings_1.default.Instance.setMailer("global", options);
    global_1.default.Instance.Mailers.delete();
};
exports.mailer.newInstance = function (options = {}, token = "") {
    settings_1.default.Instance.setMailer(token, options);
    return global_1.default.Instance.Mailers.newInstance(token);
};
exports.mailer.deleteInstance = function (token) {
    global_1.default.Instance.Mailers.delete(token);
};
exports.mailer.reset = function () {
    global_1.default.Instance.Mailers.reset();
};
//Metrics
exports.metrics = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Metrics.get();
    }
    else {
        return global_1.default.Instance.Metrics.get(token);
    }
};
exports.metrics.newInstance = function (token = "") {
    let options = {};
    options.name = token;
    settings_1.default.Instance.setMetrics(token, options);
    let registry = global_1.default.Instance.Metrics.newInstance(token);
    return registry;
};
exports.metrics.deleteInstance = function (token) {
    global_1.default.Instance.Metrics.delete(token);
};
exports.metrics.reset = function () {
    global_1.default.Instance.Metrics.reset();
};
//Metrics
exports.consul = function (token = "") {
    if (token == "") {
        return global_1.default.Instance.Consuls.get();
    }
    else {
        return global_1.default.Instance.Consuls.get(token);
    }
};
exports.consul.newInstance = function (token = "") {
    let options = {};
    options.name = token;
    settings_1.default.Instance.setConsul(token, options);
    let consul = global_1.default.Instance.Consuls.newInstance(token);
    return consul;
};
exports.consul.deleteInstance = function (token) {
    global_1.default.Instance.Consuls.delete(token);
};
exports.consul.reset = function () {
    global_1.default.Instance.Consuls.reset();
};
exports.mocks = {};
exports.mocks.redis = redisMock_1.default;
exports.mocks.cassandra = cassandraMock_1.default;
exports.mocks.elastic = elasticMock_1.default;
//Modules
exports.nock = function () {
    return require("nock");
};
exports.mocha = function () {
    return require("mocha");
};
exports.LOG_LEVEL = logger_1.default.LOG_LEVEL;
exports.AGGREGATORS = metrics_1.default.AGGREGATOR;
exports.Utils = utils_1.default;
exports.Static = statics_1.default;
//# sourceMappingURL=index.js.map