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 { Cid } from '../utils/cid.js';
import { validateAuthorizationIntegrity } from '../core/auth.js';
import { DwnInterfaceName, DwnMethodName, Message } from '../core/message.js';
export class MessagesGet extends Message {
    static parse(message) {
        return __awaiter(this, void 0, void 0, function* () {
            Message.validateJsonSchema(message);
            this.validateMessageCids(message.descriptor.messageCids);
            yield validateAuthorizationIntegrity(message);
            return new MessagesGet(message);
        });
    }
    static create(options) {
        return __awaiter(this, void 0, void 0, function* () {
            const descriptor = {
                interface: DwnInterfaceName.Messages,
                method: DwnMethodName.Get,
                messageCids: options.messageCids
            };
            const authorization = yield Message.signAsAuthorization(descriptor, options.authorizationSignatureInput);
            const message = { descriptor, authorization };
            Message.validateJsonSchema(message);
            MessagesGet.validateMessageCids(options.messageCids);
            return new MessagesGet(message);
        });
    }
    /**
     * validates the provided cids
     * @param messageCids - the cids in question
     * @throws {Error} if an invalid cid is found.
     */
    static validateMessageCids(messageCids) {
        for (const cid of messageCids) {
            try {
                Cid.parseCid(cid);
            }
            catch (_) {
                throw new Error(`${cid} is not a valid CID`);
            }
        }
    }
}
//# sourceMappingURL=messages-get.js.map