"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Subscription = /** @class */ (function () {
    function Subscription(type, header, callback, mqttSensorQueue) {
        var _this = this;
        this.behaviourBind = [];
        /**
         * Sends the given message
         *
         * @param payload the payload
         */
        this.publish = function (payload) {
            return _this.mqttSensorQueue.publish(_this.type, _this.header, payload.payload, payload.attributes, payload.type);
        };
        this.getTopic = function () { return _this.mqttSensorQueue.getTopic(_this.type, _this.header); };
        this.type = type;
        this.header = header;
        this.callback = callback;
        this.mqttSensorQueue = mqttSensorQueue;
        this.mqttSensorQueue.subscribe(type, header, callback);
    }
    /**
     * Unsubscribes from the queue
     */
    Subscription.prototype.unsubscribe = function () {
        this.behaviourBind.forEach(function (binding) { return binding.unbind(); });
        this.mqttSensorQueue.unsubscribe(this.getTopic());
    };
    /**
     * Binds the given IBehaviour to the Subscription.
     *
     * @param behaviour
     */
    Subscription.prototype.bind = function (behaviour) {
        behaviour.init(this.header.channelId);
        behaviour.bind(this);
        this.behaviourBind.push(behaviour);
    };
    Subscription.prototype.onMessage = function (message) {
        this.mqttSensorQueue.callback(this.getTopic(), message);
    };
    return Subscription;
}());
exports.Subscription = Subscription;
//# sourceMappingURL=Subscription.js.map