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 { IotizeACL } from './iotize-acl';
var ANONYMOUS_PROFILE = 'anonymous';
/**
 *
 */
var IotizeACLGroup = /** @class */ (function () {
    function IotizeACLGroup(data, bundle) {
        this.bundle = bundle;
        this.data = data;
    }
    IotizeACLGroup.prototype.toJson = function () {
        return this.data;
    };
    /**
     * Get acl for a profile
     * @param profileName
     */
    IotizeACLGroup.prototype.getByProfileName = function (profileName) {
        var e_1, _a;
        var profiles = this.listProfiles();
        try {
            for (var profiles_1 = __values(profiles), profiles_1_1 = profiles_1.next(); !profiles_1_1.done; profiles_1_1 = profiles_1.next()) {
                var profileAcl = profiles_1_1.value;
                if (profileAcl.username() === profileName) {
                    return profileAcl;
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (profiles_1_1 && !profiles_1_1.done && (_a = profiles_1.return)) _a.call(profiles_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        return IotizeACL.create(profileName, this);
    };
    IotizeACLGroup.prototype.hasRight = function (profileName, right) {
        var anonymousProfile = this.getByProfileName(ANONYMOUS_PROFILE);
        if (anonymousProfile && anonymousProfile.hasRight(right)) {
            return true;
        }
        if (profileName !== ANONYMOUS_PROFILE) {
            var profile = this.getByProfileName(profileName);
            if (profile) {
                return profile.hasRight(right);
            }
        }
        return false;
    };
    /**
     * List acl entries for each profile
     */
    IotizeACLGroup.prototype.listProfiles = function () {
        var e_2, _a;
        if (!this.data.IOTizeACL) {
            return [];
        }
        var entries = [];
        try {
            for (var _b = __values(this.data.IOTizeACL), _c = _b.next(); !_c.done; _c = _b.next()) {
                var data = _c.value;
                entries.push(new IotizeACL(data, this));
            }
        }
        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 entries;
    };
    return IotizeACLGroup;
}());
export { IotizeACLGroup };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW90aXplLWFjbC1ncm91cC5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0Bpb3RpemUvdGFwL2NvbmZpZy9pb3RpemUtc3R1ZGlvLyIsInNvdXJjZXMiOlsibGliL21vZGVsL2lvdGl6ZS1hY2wtZ3JvdXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQSxPQUFPLEVBQUUsU0FBUyxFQUFnQixNQUFNLGNBQWMsQ0FBQztBQUt2RCxJQUFNLGlCQUFpQixHQUFHLFdBQVcsQ0FBQztBQUN0Qzs7R0FFRztBQUNIO0lBR0ksd0JBQVksSUFBUyxFQUFTLE1BQTBCO1FBQTFCLFdBQU0sR0FBTixNQUFNLENBQW9CO1FBQ3BELElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDO0lBQ3JCLENBQUM7SUFFTSwrQkFBTSxHQUFiO1FBQ0ksT0FBTyxJQUFJLENBQUMsSUFBSSxDQUFDO0lBQ3JCLENBQUM7SUFFRDs7O09BR0c7SUFDSSx5Q0FBZ0IsR0FBdkIsVUFBd0IsV0FBbUI7O1FBQ3ZDLElBQUksUUFBUSxHQUFHLElBQUksQ0FBQyxZQUFZLEVBQUUsQ0FBQzs7WUFDbkMsS0FBdUIsSUFBQSxhQUFBLFNBQUEsUUFBUSxDQUFBLGtDQUFBLHdEQUFFO2dCQUE1QixJQUFJLFVBQVUscUJBQUE7Z0JBQ2YsSUFBSSxVQUFVLENBQUMsUUFBUSxFQUFFLEtBQUssV0FBVyxFQUFFO29CQUN2QyxPQUFPLFVBQVUsQ0FBQztpQkFDckI7YUF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