"use strict";
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccMessageXApi = void 0;
const icc_api_1 = require("../icc-api");
const models = require("../icc-api/model/models");
const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
const SecureDelegation_1 = require("../icc-api/model/SecureDelegation");
var AccessLevelEnum = SecureDelegation_1.SecureDelegation.AccessLevelEnum;
const utils_1 = require("./utils");
const Connection_1 = require("../icc-api/model/Connection");
const SecretIdUseOption_1 = require("./crypto/SecretIdUseOption");
class IccMessageXApi extends icc_api_1.IccMessageApi {
    get headers() {
        return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, utils_1.EntityWithDelegationTypeName.Message));
    }
    constructor(host, headers, crypto, dataOwnerApi, authApi, autofillAuthor, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), encryptedKeys = [], fetchImpl = typeof window !== 'undefined'
        ? window.fetch
        : typeof self !== 'undefined'
            ? self.fetch
            : fetch) {
        super(host, headers, authenticationProvider, fetchImpl);
        this.crypto = crypto;
        this.dataOwnerApi = dataOwnerApi;
        this.authApi = authApi;
        this.autofillAuthor = autofillAuthor;
        this.encryptedFields = (0, utils_1.parseEncryptedFields)(encryptedKeys, 'Message.');
    }
    // noinspection JSUnusedGlobalSymbols
    /**
     * Creates a new instance of message with initialised encryption metadata (not in the database).
     * @param user the current user.
     * @param m initialised data for the message. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
     * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
     * @return a new instance of message.
     */
    newInstance(user, m) {
        return this.newInstanceWithPatient(user, null, m);
    }
    /**
     * Creates a new instance of message with initialised encryption metadata (not in the database).
     * @param user the current user.
     * @param patient the patient this message refers to.
     * @param m initialised data for the message. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
     * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
     * @param options optional parameters:
     * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
     * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with
     * auto-delegations, in such case the access level specified here will be used.
     * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the message. The default value will be a
     * secret id of patient known by the topmost parent in the current data owner hierarchy.
     * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,
     * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.
     * @return a new instance of message.
     */
    newInstanceWithPatient(user_1, patient_1) {
        return __awaiter(this, arguments, void 0, function* (user, patient, m = {}, options = {}) {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
            const message = Object.assign(Object.assign({}, (m !== null && m !== void 0 ? m : {})), { _type: 'org.taktik.icure.entities.Message', id: (_a = m === null || m === void 0 ? void 0 : m.id) !== null && _a !== void 0 ? _a : this.crypto.primitives.randomUuid(), created: (_b = m === null || m === void 0 ? void 0 : m.created) !== null && _b !== void 0 ? _b : new Date().getTime(), modified: (_c = m === null || m === void 0 ? void 0 : m.modified) !== null && _c !== void 0 ? _c : new Date().getTime(), responsible: (_d = m === null || m === void 0 ? void 0 : m.responsible) !== null && _d !== void 0 ? _d : (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined), author: (_e = m === null || m === void 0 ? void 0 : m.author) !== null && _e !== void 0 ? _e : (this.autofillAuthor ? user.id : undefined), codes: (_f = m === null || m === void 0 ? void 0 : m.codes) !== null && _f !== void 0 ? _f : [], tags: (_g = m === null || m === void 0 ? void 0 : m.tags) !== null && _g !== void 0 ? _g : [] });
            const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
            if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
                throw new Error('Can only initialise entities as current data owner.');
            const sfk = patient
                ? yield this.crypto.xapi.resolveSecretIdUseOptions({ entity: patient, type: utils_1.EntityWithDelegationTypeName.Patient }, (_h = options.sfkOption) !== null && _h !== void 0 ? _h : SecretIdUseOption_1.SecretIdUseOption.UseAnySharedWithParent)
                : undefined;
            if (patient && !sfk)
                throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
            const extraDelegations = Object.assign(Object.assign({}, Object.fromEntries([...((_k = (_j = user.autoDelegations) === null || _j === void 0 ? void 0 : _j.all) !== null && _k !== void 0 ? _k : []), ...((_m = (_l = user.autoDelegations) === null || _l === void 0 ? void 0 : _l.medicalInformation) !== null && _m !== void 0 ? _m : [])].map((d) => [d, AccessLevelEnum.WRITE]))), ((_o = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _o !== void 0 ? _o : {}));
            return new models.Message(yield this.crypto.xapi
                .entityWithInitialisedEncryptedMetadata(message, utils_1.EntityWithDelegationTypeName.Message, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, extraDelegations, options.alternateRootDelegation)
                .then((x) => x.updatedEntity));
        });
    }
    /**
     * Decrypts the encrypted content of messages.
     * @param messages the messages to decrypt.
     * @return the decrypted messages with their encryption status.
     */
    decrypt(messages) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.crypto.xapi.tryDecryptEntities(messages, utils_1.EntityWithDelegationTypeName.Message, (x) => new models.Message(x));
        });
    }
    /**
     * Encrypts the content of messages.
     * @param messages the messages to encrypt.
     * @return the encrypted messages.
     */
    encrypt(messages) {
        return this.crypto.xapi.tryEncryptEntities(messages, utils_1.EntityWithDelegationTypeName.Message, this.encryptedFields, true, false, (x) => new models.Message(x));
    }
    /**
     * @param message a message
     * @return the id of the patient that the message refers to, retrieved from the encrypted metadata. Normally there should only be one element
     * in the returned array, but in case of entity merges there could be multiple values.
     */
    decryptPatientIdOf(message) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.crypto.xapi.owningEntityIdsOf({ entity: message, type: utils_1.EntityWithDelegationTypeName.Message }, undefined);
        });
    }
    /**
     * @return if the logged data owner has write access to the content of the given message
     */
    hasWriteAccess(message) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.crypto.xapi.hasWriteAccess({ entity: message, type: utils_1.EntityWithDelegationTypeName.Message });
        });
    }
    /**
     * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also
     * the encrypted content, with read-only or read-write permissions.
     * @param delegateId the id of the data owner which will be granted access to the message.
     * @param message the message to share.
     * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the
     * shared Message is the owning entity id.
     * @param options optional parameters to customize the sharing behaviour:
     * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
     * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
     * message does not have encrypted content.
     * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to
     * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
     * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.
     * @return the updated entity
     */
    shareWith(delegateId_1, message_1, shareSecretIds_1) {
        return __awaiter(this, arguments, void 0, function* (delegateId, message, shareSecretIds, options = {}) {
            return this.shareWithMany(message, { [delegateId]: Object.assign(Object.assign({}, options), { shareSecretIds }) });
        });
    }
    /**
     * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also
     * the encrypted content, with read-only or read-write permissions.
     * @param message the message to share.
     * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:
     * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the
     * shared Message is the owning entity id. Mandatory.
     * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
     * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
     * message does not have encrypted content.
     * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to
     * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
     * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.
     * @return the updated entity
     */
    shareWithMany(message, delegates) {
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.tryShareWithMany(message, delegates)).updatedEntityOrThrow;
        });
    }
    /**
     * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also
     * the encrypted content, with read-only or read-write permissions.
     * @param message the message to share.
     * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:
     * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the
     * shared Message is the owning entity id. Mandatory.
     * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
     * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
     * message does not have encrypted content.
     * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to
     * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
     * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.
     * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if
     * the operation failed.
     */
    tryShareWithMany(message, delegates) {
        const _super = Object.create(null, {
            bulkShareMessages: { get: () => super.bulkShareMessages }
        });
        return __awaiter(this, void 0, void 0, function* () {
            // All entities should have an encryption key.
            const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(message, utils_1.EntityWithDelegationTypeName.Message);
            const updatedEntity = entityWithEncryptionKey ? yield this.modifyMessageWithUser(undefined, entityWithEncryptionKey) : message;
            return this.crypto.xapi
                .simpleShareOrUpdateEncryptedEntityMetadata({
                entity: updatedEntity,
                type: utils_1.EntityWithDelegationTypeName.Message,
            }, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
                delegateId,
                {
                    requestedPermissions: options.requestedPermissions,
                    shareEncryptionKeys: options.shareEncryptionKey,
                    shareOwningEntityIds: options.sharePatientId,
                    shareSecretIds: options.shareSecretIds,
                },
            ])), (x) => _super.bulkShareMessages.call(this, x))
                .then((r) => r.mapSuccessAsync((m) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt([m]))[0].entity; })));
        });
    }
    /**
     * @param message a message
     * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is
     * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.
     */
    decryptSecretIdsOf(message) {
        return this.crypto.xapi.secretIdsOf({ entity: message, type: utils_1.EntityWithDelegationTypeName.Message }, undefined);
    }
    /**
     * Creates or updates de-anonymization metadata for the message, allowing resolution of anonymous delegations.
     * @param entity the message.
     * @param delegates the data owner ids of the delegates.
     */
    createDelegationDeAnonymizationMetadata(entity, delegates) {
        return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: utils_1.EntityWithDelegationTypeName.Message }, delegates);
    }
    /**
     * Retrieves the data owners that have access to the message.
     * @param entity the message.
     * @return the data owners with their access levels and a flag indicating if there are unknown anonymous data owners.
     */
    getDataOwnersWithAccessTo(entity) {
        return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: utils_1.EntityWithDelegationTypeName.Message });
    }
    /**
     * Retrieves the encryption keys of the message.
     * @param entity the message.
     * @return the encryption keys.
     */
    getEncryptionKeysOf(entity) {
        return this.crypto.xapi.encryptionKeysOf({ entity, type: utils_1.EntityWithDelegationTypeName.Message }, undefined);
    }
    /**
     * Subscribes to message events (create, update, delete).
     * @param eventTypes the types of events to subscribe to.
     * @param filter optional filter to apply to the events.
     * @param eventFired callback function to be called when an event is fired.
     * @param options optional subscription options.
     * @return a connection that can be used to close the subscription.
     */
    subscribeToMessageEvents(eventTypes_1, filter_1, eventFired_1) {
        return __awaiter(this, arguments, void 0, function* (eventTypes, filter, eventFired, options = {}) {
            return yield (0, utils_1.subscribeToEntityEvents)(this.host, this.authApi, utils_1.EntityWithDelegationTypeName.Message, eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt([encrypted]))[0].entity; })).then((rs) => new Connection_1.ConnectionImpl(rs));
        });
    }
    decryptPage(page) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a;
            return Object.assign(Object.assign({}, page), { rows: (yield this.decrypt((_a = page.rows) !== null && _a !== void 0 ? _a : [])).map((x) => x.entity) });
        });
    }
    /**
     * Creates a message.
     * @param user the current user (unused, for compatibility).
     * @param body the message to create.
     * @return the created message.
     */
    createMessageWithUser(user, body) {
        const _super = Object.create(null, {
            createMessage: { get: () => super.createMessage }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt([yield _super.createMessage.call(this, (yield this.encrypt([body]))[0])]))[0].entity;
        });
    }
    /**
     * Finds messages with pagination.
     * @param user the current user (unused, for compatibility).
     * @param startKey optional start key for pagination.
     * @param startDocumentId optional start document id for pagination.
     * @param limit optional maximum number of results to return.
     * @return a paginated list of messages.
     */
    findMessagesWithUser(user, startKey, startDocumentId, limit) {
        const _super = Object.create(null, {
            findMessages: { get: () => super.findMessages }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.decryptPage(yield _super.findMessages.call(this, startKey, startDocumentId, limit));
        });
    }
    /**
     * Finds messages by sender address with pagination.
     * @param user the current user (unused, for compatibility).
     * @param fromAddress the sender address to filter by.
     * @param startKey optional start key for pagination.
     * @param startDocumentId optional start document id for pagination.
     * @param limit optional maximum number of results to return.
     * @param hcpId optional healthcare party id to filter by.
     * @return a paginated list of messages.
     */
    findMessagesByFromAddressWithUser(user, fromAddress, startKey, startDocumentId, limit, hcpId) {
        const _super = Object.create(null, {
            findMessagesByFromAddress: { get: () => super.findMessagesByFromAddress }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.decryptPage(yield _super.findMessagesByFromAddress.call(this, fromAddress, startKey, startDocumentId, limit, hcpId));
        });
    }
    /**
     * @deprecated
     */
    findMessagesByHCPartyPatientForeignKeysUsingPostWithUser(user, body) {
        const _super = Object.create(null, {
            findMessagesByHCPartyPatientForeignKeysUsingPost: { get: () => super.findMessagesByHCPartyPatientForeignKeysUsingPost }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.findMessagesByHCPartyPatientForeignKeysUsingPost.call(this, body))).map((x) => x.entity);
        });
    }
    /**
     * @deprecated
     */
    findMessagesByHCPartyPatientForeignKeysWithUser(user, secretFKeys) {
        const _super = Object.create(null, {
            findMessagesByHCPartyPatientForeignKeys: { get: () => super.findMessagesByHCPartyPatientForeignKeys }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.findMessagesByHCPartyPatientForeignKeys.call(this, secretFKeys))).map((x) => x.entity);
        });
    }
    /**
     * Finds messages by recipient address with pagination.
     * @param user the current user (unused, for compatibility).
     * @param toAddress the recipient address to filter by.
     * @param startKey optional start key for pagination.
     * @param startDocumentId optional start document id for pagination.
     * @param limit optional maximum number of results to return.
     * @param reverse optional flag to reverse the sort order.
     * @param hcpId optional healthcare party id to filter by.
     * @return a paginated list of messages.
     */
    findMessagesByToAddressWithUser(user, toAddress, startKey, startDocumentId, limit, reverse, hcpId) {
        const _super = Object.create(null, {
            findMessagesByToAddress: { get: () => super.findMessagesByToAddress }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.decryptPage(yield _super.findMessagesByToAddress.call(this, toAddress, startKey, startDocumentId, limit, reverse, hcpId));
        });
    }
    /**
     * Finds messages by transport GUID with pagination.
     * @param user the current user (unused, for compatibility).
     * @param transportGuid the transport GUID to filter by.
     * @param received optional flag to filter by received status.
     * @param startKey optional start key for pagination.
     * @param startDocumentId optional start document id for pagination.
     * @param limit optional maximum number of results to return.
     * @param hcpId optional healthcare party id to filter by.
     * @return a paginated list of messages.
     */
    findMessagesByTransportGuidWithUser(user, transportGuid, received, startKey, startDocumentId, limit, hcpId) {
        const _super = Object.create(null, {
            findMessagesByTransportGuid: { get: () => super.findMessagesByTransportGuid }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.decryptPage(yield _super.findMessagesByTransportGuid.call(this, transportGuid, received, startKey, startDocumentId, limit, hcpId));
        });
    }
    /**
     * Finds messages by transport GUID and sent date range with pagination.
     * @param user the current user (unused, for compatibility).
     * @param transportGuid the transport GUID to filter by.
     * @param from optional start timestamp for the date range.
     * @param to optional end timestamp for the date range.
     * @param startKey optional start key for pagination.
     * @param startDocumentId optional start document id for pagination.
     * @param limit optional maximum number of results to return.
     * @param hcpId optional healthcare party id to filter by.
     * @return a paginated list of messages.
     */
    findMessagesByTransportGuidSentDateWithUser(user, transportGuid, from, to, startKey, startDocumentId, limit, hcpId) {
        const _super = Object.create(null, {
            findMessagesByTransportGuidSentDate: { get: () => super.findMessagesByTransportGuidSentDate }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.decryptPage(yield _super.findMessagesByTransportGuidSentDate.call(this, transportGuid, from, to, startKey, startDocumentId, limit, hcpId));
        });
    }
    /**
     * Retrieves the children messages of a message.
     * @param user the current user (unused, for compatibility).
     * @param messageId the id of the parent message.
     * @return the children messages.
     */
    getChildrenMessagesWithUser(user, messageId) {
        const _super = Object.create(null, {
            getChildrenMessages: { get: () => super.getChildrenMessages }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.getChildrenMessages.call(this, messageId))).map((x) => x.entity);
        });
    }
    /**
     * Retrieves the children messages of a list of parent messages.
     * @param user the current user (unused, for compatibility).
     * @param body the list of parent message ids.
     * @return the children messages.
     */
    getChildrenMessagesOfListWithUser(user, body) {
        const _super = Object.create(null, {
            getChildrenMessagesOfList: { get: () => super.getChildrenMessagesOfList }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.getChildrenMessagesOfList.call(this, body))).map((x) => x.entity);
        });
    }
    /**
     * Retrieves a message by its id.
     * @param user the current user (unused, for compatibility).
     * @param messageId the id of the message.
     * @return the message.
     */
    getMessageWithUser(user, messageId) {
        const _super = Object.create(null, {
            getMessage: { get: () => super.getMessage }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt([yield _super.getMessage.call(this, messageId)]))[0].entity;
        });
    }
    /**
     * Retrieves multiple messages by their ids.
     * @param user the current user (unused, for compatibility).
     * @param messageIds the list of message ids.
     * @return the messages.
     */
    getMessagesWithUser(user, messageIds) {
        const _super = Object.create(null, {
            getMessages: { get: () => super.getMessages }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.getMessages.call(this, messageIds))).map((x) => x.entity);
        });
    }
    /**
     * Lists messages by invoice ids.
     * @param user the current user (unused, for compatibility).
     * @param body the list of invoice ids.
     * @return the messages associated with the invoices.
     */
    listMessagesByInvoiceIdsWithUser(user, body) {
        const _super = Object.create(null, {
            listMessagesByInvoiceIds: { get: () => super.listMessagesByInvoiceIds }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.listMessagesByInvoiceIds.call(this, body))).map((x) => x.entity);
        });
    }
    /**
     * Lists messages by transport GUIDs.
     * @param user the current user (unused, for compatibility).
     * @param hcpId the healthcare party id.
     * @param body the list of transport GUIDs.
     * @return the messages associated with the transport GUIDs.
     */
    listMessagesByTransportGuidsWithUser(user, hcpId, body) {
        const _super = Object.create(null, {
            listMessagesByTransportGuids: { get: () => super.listMessagesByTransportGuids }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.listMessagesByTransportGuids.call(this, hcpId, body))).map((x) => x.entity);
        });
    }
    /**
     * Modifies a message.
     * @param user the current user (unused, for compatibility).
     * @param body the message to modify.
     * @return the modified message.
     */
    modifyMessageWithUser(user, body) {
        const _super = Object.create(null, {
            modifyMessage: { get: () => super.modifyMessage }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt([yield _super.modifyMessage.call(this, (yield this.encrypt([body]))[0])]))[0].entity;
        });
    }
    /**
     * Sets the status bits of multiple messages.
     * @param user the current user (unused, for compatibility).
     * @param status the status bits to set.
     * @param body the list of message ids.
     * @return the updated messages.
     */
    setMessagesStatusBitsWithUser(user, status, body) {
        const _super = Object.create(null, {
            setMessagesStatusBits: { get: () => super.setMessagesStatusBits }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.setMessagesStatusBits.call(this, status, body))).map((x) => x.entity);
        });
    }
    filterMessagesByWithUser(user_1, body_1, startDocumentId_1, limit_1) {
        const _super = Object.create(null, {
            filterMessagesBy: { get: () => super.filterMessagesBy }
        });
        return __awaiter(this, arguments, void 0, function* (user, body, startDocumentId, limit, collectTiming = false) {
            return yield this.decryptPage(yield _super.filterMessagesBy.call(this, body, startDocumentId, limit, collectTiming));
        });
    }
    /**
     * Sets the read status of multiple messages.
     * @param user the current user (unused, for compatibility).
     * @param body the read status update information.
     * @return the updated messages.
     */
    setMessagesReadStatusWithUser(user, body) {
        const _super = Object.create(null, {
            setMessagesReadStatus: { get: () => super.setMessagesReadStatus }
        });
        return __awaiter(this, void 0, void 0, function* () {
            return (yield this.decrypt(yield _super.setMessagesReadStatus.call(this, body))).map((x) => x.entity);
        });
    }
    createMessage(body) {
        throw new Error('Use withUser method');
    }
    findMessages(startKey, startDocumentId, limit) {
        throw new Error('Use withUser method');
    }
    findMessagesByFromAddress(fromAddress, startKey, startDocumentId, limit, hcpId) {
        throw new Error('Use withUser method');
    }
    findMessagesByHCPartyPatientForeignKeysUsingPost(body) {
        throw new Error('Use withUser method');
    }
    findMessagesByHCPartyPatientForeignKeys(secretFKeys) {
        throw new Error('Use withUser method');
    }
    findMessagesByToAddress(toAddress, startKey, startDocumentId, limit, reverse, hcpId) {
        throw new Error('Use withUser method');
    }
    findMessagesByTransportGuid(transportGuid, received, startKey, startDocumentId, limit, hcpId) {
        throw new Error('Use withUser method');
    }
    findMessagesByTransportGuidSentDate(transportGuid, from, to, startKey, startDocumentId, limit, hcpId) {
        throw new Error('Use withUser method');
    }
    getChildrenMessages(messageId) {
        throw new Error('Use withUser method');
    }
    getChildrenMessagesOfList(body) {
        throw new Error('Use withUser method');
    }
    getMessage(messageId) {
        throw new Error('Use withUser method');
    }
    getMessages(messageIds) {
        throw new Error('Use withUser method');
    }
    listMessagesByInvoiceIds(body) {
        throw new Error('Use withUser method');
    }
    listMessagesByTransportGuids(hcpId, body) {
        throw new Error('Use withUser method');
    }
    modifyMessage(body) {
        throw new Error('Use withUser method');
    }
    setMessagesStatusBits(status, body) {
        throw new Error('Use withUser method');
    }
    filterMessagesBy(body, startDocumentId, limit) {
        throw new Error('Use withUser method');
    }
    setMessagesReadStatus(body) {
        throw new Error('Use withUser method');
    }
}
exports.IccMessageXApi = IccMessageXApi;
//# sourceMappingURL=icc-message-x-api.js.map