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 { DwnInterfaceName, DwnMethodName, Message } from '../core/message.js';
/**
 * Class that provides `HooksWrite` related operations.
 */
export class HooksWrite extends Message {
    /**
     * Creates a HooksWrite message
     */
    static create(options) {
        var _a;
        return __awaiter(this, void 0, void 0, function* () {
            const descriptor = {
                interface: DwnInterfaceName.Hooks,
                method: DwnMethodName.Write,
                dateCreated: (_a = options.dateCreated) !== null && _a !== void 0 ? _a : getCurrentTimeInHighPrecision(),
                uri: options.uri,
                filter: options.filter
            };
            // delete all descriptor properties that are `undefined` else the code will encounter the following IPLD issue when attempting to generate CID:
            // Error: `undefined` is not supported by the IPLD Data Model and cannot be encoded
            removeUndefinedProperties(descriptor);
            const authorization = yield Message.signAsAuthorization(descriptor, options.authorizationSignatureInput);
            const message = { descriptor, authorization };
            Message.validateJsonSchema(message);
            const hooksWrite = new HooksWrite(message);
            return hooksWrite;
        });
    }
}
//# sourceMappingURL=hooks-write.js.map