"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBus = void 0;
const utils_1 = require("../utils");
const DfnsBus_1 = require("./DfnsBus");
var BusConfig;
(function (BusConfig) {
    BusConfig["RABBITMQ_CREDENTIALS"] = "RABBITMQ_CREDENTIALS";
    BusConfig["RABBITMQ_URL"] = "RABBITMQ_URL";
    BusConfig["ENVIRONMENT"] = "ENVIRONMENT";
    BusConfig["BUSINESS_DOMAIN"] = "BUSINESS_DOMAIN";
    BusConfig["SERVICE_NAME"] = "SERVICE_NAME";
})(BusConfig || (BusConfig = {}));
let _dfnsBus;
const getBus = async () => {
    const exchangeName = 'main-exchange';
    const busConfig = await (0, utils_1.loadEnvVars)(BusConfig);
    const busSecretsParsed = JSON.parse(busConfig.RABBITMQ_CREDENTIALS);
    if (!_dfnsBus) {
        const originator = `${busConfig.ENVIRONMENT}-${busConfig.BUSINESS_DOMAIN}-${busConfig.SERVICE_NAME}`;
        _dfnsBus = new DfnsBus_1.DfnsBus(originator, exchangeName, {
            protocol: 'amqps',
            hostname: busConfig.RABBITMQ_URL,
            username: busSecretsParsed.username,
            password: busSecretsParsed.password,
            port: 5671,
        });
        await _dfnsBus.init();
    }
    return _dfnsBus;
};
exports.getBus = getBus;
//# sourceMappingURL=dfnsBusFactory.js.map