var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { IotizeVariableModel } from './iotize-variable-model';
import { IotizeProfileModel } from './iotize-profile-model';
import { VariableDoesNotExistError } from './iotize-config-model';
import { InvalidConfigurationError } from './invalid-configuration-error';
import { IotizeACLGroup } from './iotize-acl-group';
var IotizeBundleModel = /** @class */ (function () {
    function IotizeBundleModel(data, iotizeModule) {
        this.data = data;
        this.iotizeModule = iotizeModule;
    }
    IotizeBundleModel.prototype.toJson = function () {
        return this.data;
    };
    IotizeBundleModel.prototype.module = function () {
        return this.iotizeModule;
    };
    IotizeBundleModel.prototype.id = function () {
        if (!this.data.$.Id) {
            throw new InvalidConfigurationError('This bundle does not have an id');
        }
        return this.data.$.Id;
    };
    IotizeBundleModel.prototype.name = function () {
        return this.data.$.GUI_Name || '#' + this.id();
    };
    IotizeBundleModel.prototype.dataLogPeriod = function () {
        if (!this.data.$.DataLogPeriod) {
            return 0;
        }
        return Number(this.data.$.DataLogPeriod);
    };
    IotizeBundleModel.prototype.hasDataLog = function () {
        return this.dataLogPeriod() > 0;
    };
    IotizeBundleModel.prototype.description = function () {
        return this.data.$.GUI_Description;
    };
    IotizeBundleModel.prototype.variable = function (variableId) {
        var e_1, _a;
        try {
            for (var _b = __values(this.variables()), _c = _b.next(); !_c.done; _c = _b.next()) {
                var variable = _c.value;
                if (variable.id() === variableId) {
                    return variable;
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
        throw new VariableDoesNotExistError(variableId, this.iotizeModule);
    };
    IotizeBundleModel.prototype.hasVariable = function (variableId) {
        var e_2, _a;
        try {
            for (var _b = __values(this.variables()), _c = _b.next(); !_c.done; _c = _b.next()) {
                var variable = _c.value;
                if (variable.id() === variableId) {
                    return variable;
                }
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_2) throw e_2.error; }
        }
        return false;
    };
    IotizeBundleModel.prototype.profiles = function () {
        var e_3, _a;
        if (!this.data.IOTizeAccessControl) {
            return [];
        }
        var profiles = [];
        try {
            for (var _b = __values(this.data.IOTizeAccessControl), _c = _b.next(); !_c.done; _c = _b.next()) {
                var profile = _c.value;
                profiles.push(new IotizeProfileModel(profile));
            }
        }
        catch (e_3_1) { e_3 = { error: e_3_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_3) throw e_3.error; }
        }
        return profiles;
    };
    IotizeBundleModel.prototype.variables = function () {
        var e_4, _a;
        if (!this.data.IOTizeVariable) {
            return [];
        }
        var variables = [];
        try {
            for (var _b = __values(this.data.IOTizeVariable), _c = _b.next(); !_c.done; _c = _b.next()) {
                var variable = _c.value;
                variables.push(new IotizeVariableModel(variable, this.iotizeModule, this));
            }
        }
        catch (e_4_1) { e_4 = { error: e_4_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_4) throw e_4.error; }
        }
        return variables;
    };
    IotizeBundleModel.prototype.getACLGroup = function () {
        var data = {};
        if (!this.data.IOTizeAccessControl) {
            this.data.IOTizeAccessControl = [];
        }
        if (this.data.IOTizeAccessControl.length > 0) {
            data = this.data.IOTizeAccessControl[0];
        }
        return new IotizeACLGroup(data, this);
    };
    return IotizeBundleModel;
}());
export { IotizeBundleModel };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW90aXplLWJ1bmRsZS1tb2RlbC5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0B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