"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Subscription_1 = require("./Subscription");
var dist_1 = require("@leftshiftone/gaia-sdk/dist");
var EventType_1 = require("../event/EventType");
var EventStream_1 = require("../event/EventStream");
var KeyboardBehaviour_1 = require("../behaviour/KeyboardBehaviour");
var MouseBehaviour_1 = require("../behaviour/MouseBehaviour");
var MessageType_1 = require("../support/MessageType");
var InteractionSubscription = /** @class */ (function (_super) {
    __extends(InteractionSubscription, _super);
    function InteractionSubscription(header, callback, mqttSensorQueue, renderer) {
        var _this = _super.call(this, dist_1.ConversationQueueType.INTERACTION, header, callback, mqttSensorQueue) || this;
        _this.renderer = renderer;
        _this.renderer.init(header.channelId);
        var ev = EventType_1.EventType.withChannelId(EventType_1.EventType.PUBLISH, _this.header.channelId);
        EventStream_1.default.addListener(ev, function (e) { return _this.publish(e[0]); });
        return _this;
    }
    /**
     * Initial request to make the system aware that the user is listening.
     */
    InteractionSubscription.prototype.reception = function (attributes) {
        if (this.behaviourBind.length === 0) {
            this.bind(new KeyboardBehaviour_1.KeyboardBehaviour(this.renderer));
            this.bind(new MouseBehaviour_1.MouseBehaviour(this.renderer));
        }
        this.mqttSensorQueue.publishConvInteraction(this.header, { attributes: attributes, payload: {}, type: MessageType_1.MessageType.RECEPTION });
    };
    InteractionSubscription.prototype.onMessage = function (message) {
        var _this = this;
        var spec = message;
        if (spec.type !== "reception" && spec.elements) {
            spec = Object.assign(spec, { position: 'left', channelId: this.header.channelId });
            this.renderer.render(spec).forEach(function (element) {
                _this.renderer.appendContent(element);
            });
        }
        _super.prototype.onMessage.call(this, message);
    };
    return InteractionSubscription;
}(Subscription_1.Subscription));
exports.InteractionSubscription = InteractionSubscription;
//# sourceMappingURL=InteractionSubscription.js.map