"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ConversationLanguageResolver_1 = require("../language/ConversationLanguageResolver");
var InteractionInterceptor_1 = require("./InteractionInterceptor");
/**
 * Intercepts all messages from convey before they are sent and enrich the attributes with the conversation language
 */
var DefaultInteractionInterceptor = /** @class */ (function () {
    function DefaultInteractionInterceptor() {
        this.languageResolver = new ConversationLanguageResolver_1.ConversationLanguageResolver();
    }
    /**
     * It goes through all language providers to extract the conversation language and enrich the attributes of the interaction with it.
     * Should the attributes contain the language, this will not be modified.
     *
     * @param interaction ConveyInteraction
     */
    DefaultInteractionInterceptor.prototype.execute = function (interaction) {
        if (interaction["attributes"][InteractionInterceptor_1.INTERNAL_LANGUAGE] !== undefined) {
            console.log("Conversation language already in attributes with value: " + interaction["attributes"][InteractionInterceptor_1.INTERNAL_LANGUAGE]);
            return interaction;
        }
        var conversationLanguage = this.languageResolver.get();
        if (conversationLanguage === undefined) {
            console.error("No conversation language defined!!!!!");
        }
        interaction["attributes"][InteractionInterceptor_1.INTERNAL_LANGUAGE] = conversationLanguage;
        return interaction;
    };
    return DefaultInteractionInterceptor;
}());
exports.DefaultInteractionInterceptor = DefaultInteractionInterceptor;
//# sourceMappingURL=DefaultInteractionInterceptor.js.map