var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { getCurrentTimeInHighPrecision } from '../utils/time.js';
import { removeUndefinedProperties } from '../utils/object.js';
import { validateAuthorizationIntegrity } from '../core/auth.js';
import { DwnInterfaceName, DwnMethodName, Message } from '../core/message.js';
export class PermissionsRequest extends Message {
    static parse(message) {
        return __awaiter(this, void 0, void 0, function* () {
            yield validateAuthorizationIntegrity(message);
            return new PermissionsRequest(message);
        });
    }
    static create(options) {
        var _a;
        return __awaiter(this, void 0, void 0, function* () {
            const descriptor = {
                interface: DwnInterfaceName.Permissions,
                method: DwnMethodName.Request,
                messageTimestamp: (_a = options.messageTimestamp) !== null && _a !== void 0 ? _a : getCurrentTimeInHighPrecision(),
                description: options.description,
                grantedTo: options.grantedTo,
                grantedBy: options.grantedBy,
                grantedFor: options.grantedFor,
                scope: options.scope,
                conditions: options.conditions,
            };
            removeUndefinedProperties(descriptor);
            const auth = yield Message.signAsAuthorization(descriptor, options.authorizationSignatureInput);
            const message = { descriptor, authorization: auth };
            Message.validateJsonSchema(message);
            return new PermissionsRequest(message);
        });
    }
}
//# sourceMappingURL=permissions-request.js.map