"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseAuthorizationManager = void 0;
const ContentTypes_1 = require("../util/ContentTypes");
const NotFoundHttpError_1 = require("../util/errors/NotFoundHttpError");
const StreamUtil_1 = require("../util/StreamUtil");
/**
 * An {@link AuthorizationManager} that gets parent identifiers from an {@link IdentifierStrategy}
 * and authorization data by using an {@link AuxiliaryIdentifierStrategy} and a {@link ResourceStore}.
 */
class BaseAuthorizationManager {
    identifierStrategy;
    authStrategy;
    store;
    constructor(identifierStrategy, authStrategy, store) {
        this.identifierStrategy = identifierStrategy;
        this.authStrategy = authStrategy;
        this.store = store;
    }
    getParent(id) {
        const identifier = { path: id };
        if (this.identifierStrategy.isRootContainer(identifier)) {
            return;
        }
        return this.identifierStrategy.getParentContainer(identifier).path;
    }
    async getAuthorizationData(id) {
        try {
            const identifier = this.authStrategy.getAuxiliaryIdentifier({ path: id });
            const representation = await this.store.getRepresentation(identifier, { type: { [ContentTypes_1.INTERNAL_QUADS]: 1 } });
            return await (0, StreamUtil_1.arrayifyStream)(representation.data);
        }
        catch (err) {
            if (NotFoundHttpError_1.NotFoundHttpError.isInstance(err)) {
                return;
            }
            throw err;
        }
    }
}
exports.BaseAuthorizationManager = BaseAuthorizationManager;
//# sourceMappingURL=BaseAuthorizationManager.js.map