"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.IccHelementApi = void 0;
/**
 * iCure Data Stack API Documentation
 * The iCure Data Stack Application API is the native interface to iCure. This version is obsolete, please use v2.
 *
 * OpenAPI spec version: v1
 *
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */
const XHR_1 = require("./XHR");
const DocIdentifier_1 = require("../model/DocIdentifier");
const HealthElement_1 = require("../model/HealthElement");
const IcureStub_1 = require("../model/IcureStub");
const ListOfIds_1 = require("../model/ListOfIds");
const PaginatedListHealthElement_1 = require("../model/PaginatedListHealthElement");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const EntityBulkShareResult_1 = require("../model/requests/EntityBulkShareResult");
const MinimalEntityBulkShareResult_1 = require("../model/requests/MinimalEntityBulkShareResult");
class IccHelementApi {
    get headers() {
        return Promise.resolve(this._headers);
    }
    constructor(host, headers, authenticationProvider, fetchImpl) {
        this.host = (0, IccRestApiPath_1.iccRestApiPath)(host);
        this._headers = Object.keys(headers).map((k) => new XHR_1.XHR.Header(k, headers[k]));
        this.authenticationProvider = !!authenticationProvider ? authenticationProvider : new AuthenticationProvider_1.NoAuthenticationProvider();
        this.fetchImpl = fetchImpl;
    }
    setHeaders(h) {
        this._headers = h;
    }
    handleError(e) {
        throw e;
    }
    /**
     * Returns an instance of created healthcare element.
     * @summary Create a healthcare element with the current user
     * @param body
     */
    createHealthElement(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/helement` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new HealthElement_1.HealthElement(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the created healthcare elements.
     * @summary Create a batch of healthcare elements
     * @param body
     */
    createHealthElements(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/helement/batch` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new HealthElement_1.HealthElement(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Delete healthcare elements by batch.
     *
     * @param healthElementIds a ListOfIds containing the ids of the health elements to delete.
     * @return a Promise that will resolve in an Array containing the DocIdentifiers of the successfully delete documents.
     */
    deleteHealthElements(healthElementIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const headers = (yield this.headers).filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', this.host + `/helement/delete/batch` + '?ts=' + new Date().getTime(), headers, healthElementIds, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new DocIdentifier_1.DocIdentifier(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a single health element by id.
     *
     * @param healthElementId the id of the health element to delete.
     * @return a Promise that will resolve in the DocIdentifier of the deleted health element.
     */
    deleteHealthElement(healthElementId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/helement/${encodeURIComponent(healthElementId)}` + '?ts=' + new Date().getTime(), yield this.headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    filterHealthElementsBy(startDocumentId_1, limit_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (startDocumentId, limit, body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/helement/filter` +
                '?ts=' +
                new Date().getTime() +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(new PaginatedListHealthElement_1.PaginatedListHealthElement(doc.body), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary List healthcare elements found By Healthcare Party and secret foreign keys.
     * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead.
     * @param body
     * @param hcPartyId
     */
    findHealthElementsByHCPartyPatientForeignKeysUsingPost(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/helement/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new HealthElement_1.HealthElement(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by commas.
     * @deprecated use {@link findHealthElementIdsByDataOwnerPatientOpeningDate} instead.
     * @summary List healthcare elements found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     */
    findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/helement/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new HealthElement_1.HealthElement(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary List HealthElement ids by data owner and a set of secret foreign key. The ids will be sorted by HealthElement openingDate, in ascending or descending
     * order according to the specified parameter value.
     *
     * @param dataOwnerId the data owner id.
     * @param secretFKeys an array of secret foreign keys.
     * @param startDate a timestamp in epoch milliseconds. If undefined, all the health element ids since the beginning of time will be returned.
     * @param endDate a timestamp in epoch milliseconds. If undefined, all the health element ids until the end of time will be returned.
     * @param descending whether to return the ids ordered in ascending or descending order by HealthElement openingDate
     * @return a promise that will resolve in an Array of HealthElement ids.
     */
    findHealthElementIdsByDataOwnerPatientOpeningDate(dataOwnerId, secretFKeys, startDate, endDate, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/helement/byDataOwnerPatientOpeningDate?ts=${new Date().getTime()}` +
                '&dataOwnerId=' +
                encodeURIComponent(dataOwnerId) +
                (!!startDate ? `&startDate=${encodeURIComponent(startDate)}` : '') +
                (!!endDate ? `&endDate=${encodeURIComponent(endDate)}` : '') +
                (!!descending ? `&descending=${descending}` : '');
            const headers = (yield this.headers).filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            const body = new ListOfIds_1.ListOfIds({ ids: secretFKeys });
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => JSON.parse(JSON.stringify(it))))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated use {@link findHealthElementsDelegationsStubsByIds} instead.
     * @summary List helement stubs found By Healthcare Party and secret foreign keys.
     * @param body
     * @param hcPartyId
     */
    findHealthElementsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/helement/byHcPartySecretForeignKeys/delegations` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new IcureStub_1.IcureStub(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by coma
     * @deprecated use {@link findHealthElementsDelegationsStubsByIds} instead.
     * @summary List helement stubs found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     */
    findHealthElementsDelegationsStubsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/helement/byHcPartySecretForeignKeys/delegations` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new IcureStub_1.IcureStub(it)))
                .catch((err) => this.handleError(err));
        });
    }
    findHealthElementsDelegationsStubsByIds(healthElementIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/helement/byHcPartySecretForeignKeys/delegations`;
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, { ids: healthElementIds }, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new IcureStub_1.IcureStub(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get a healthcare element
     * @param healthElementId
     */
    getHealthElement(healthElementId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/helement/${encodeURIComponent(String(healthElementId))}` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new HealthElement_1.HealthElement(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Get a list of healthElement by ids/keys.
     * @summary Get healthElements by batch
     * @param body
     */
    getHealthElements(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/helement/byIds` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new HealthElement_1.HealthElement(it)))
                .catch((err) => this.handleError(err));
        });
    }
    matchHealthElementsBy(body_1) {
        return __awaiter(this, arguments, void 0, function* (body, collectTiming = false) {
            const _url = this.host + `/helement/match` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(doc.body.map((it) => JSON.parse(JSON.stringify(it))), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified healthcare element.
     * @summary Modify a healthcare element
     * @param body
     */
    modifyHealthElement(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/helement` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new HealthElement_1.HealthElement(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified healthcare elements.
     * @summary Modify a batch of healthcare elements
     * @param body
     */
    modifyHealthElements(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/helement/batch` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new HealthElement_1.HealthElement(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareHealthElements(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/helement/bulkSharedMetadataUpdate' + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, request, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((x) => new EntityBulkShareResult_1.EntityBulkShareResult(x, HealthElement_1.HealthElement)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareHealthElementsMinimal(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/helement/bulkSharedMetadataUpdateMinimal' + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, request, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((x) => new MinimalEntityBulkShareResult_1.MinimalEntityBulkShareResult(x)))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccHelementApi = IccHelementApi;
//# sourceMappingURL=IccHelementApi.js.map