"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var default_variable_monitor_1 = require("./monitor/default-variable-monitor");
var response_error_1 = require("../../client/api/response/response-error");
var TlvBundleConverter_1 = require("../extra-converter/TlvBundleConverter");
// import { TLVConverter } from '../../client/impl/converter/tlv-converter';
var Bundle = /** @class */ (function () {
    function Bundle(identifier, bundleId, bundleService, variables) {
        this.identifier = identifier;
        this.bundleId = bundleId;
        this.bundleService = bundleService;
        this.variables = variables;
        this.converter = new TlvBundleConverter_1.TlvBundleConverter(variables);
    }
    Bundle.prototype.read = function () {
        var _this = this;
        return this
            .bundleService
            .getValues(this.bundleId)
            .then(function (response) {
            if (!response.isSuccess()) {
                throw new Error("Cannot read bundle " + _this.identifier + ". Cause: " + new response_error_1.ResponseError(response));
            }
            var rawBody = response.rawBody();
            return _this.converter.decode(rawBody);
        });
    };
    Bundle.prototype.monitor = function () {
        var _this = this;
        if (!this._monitor) {
            this._monitor = new default_variable_monitor_1.DefaultVariableMonitor({
                update: function (count) {
                    console.debug("Request monitor update on " + _this.identifier);
                    return _this.read();
                }
            });
        }
        return this._monitor;
    };
    return Bundle;
}());
exports.Bundle = Bundle;
