"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PermissionsClient = void 0;
const Foundations_1 = require("@dfns/datamodel/dist/Foundations");
const constants_1 = require("../constants");
class PermissionsClient {
    constructor(client) {
        this.client = client;
    }
    async verifyAuthorization(body) {
        const path = constants_1.PRIVATE_ENDPOINTS.PermissionsVerifyAuthorization.path;
        const resp = await this.client.post(path, body);
        if (!resp.data.isAuthorized)
            throw new Foundations_1.ForbiddenError(`${body.identityKind} with id ${body.identityId} is not authorized to perform operation ${body.operation}`, body.serviceName);
    }
    async listAssignedPermissions(body) {
        const path = constants_1.PRIVATE_ENDPOINTS.PermissionsListAssignedPermissions.path;
        const resp = await this.client.post(path, body);
        return resp.data;
    }
    async createResourceOwnership(body) {
        const path = constants_1.PRIVATE_ENDPOINTS.PermissionsCreateResourceOwnership.path;
        const resp = await this.client.post(path, body);
        return resp.data;
    }
    async getDynamoPermissionAwareQuery(body) {
        const path = constants_1.PRIVATE_ENDPOINTS.PermissionsGetDynamoPermissionAwareQuery.path;
        const resp = await this.client.post(path, body);
        if (!resp.data.isAuthorized)
            throw new Foundations_1.ForbiddenError(`${body.identityKind} with id ${body.identityId} is not authorized to perform operation ${body.operation}`, body.serviceName);
        return resp.data;
    }
    async getPermittedResourceIds(body) {
        const path = constants_1.PRIVATE_ENDPOINTS.PermissionsGetPermittedResourceIds.path;
        const resp = await this.client.post(path, body);
        return resp.data;
    }
}
exports.PermissionsClient = PermissionsClient;
