"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccIcureApi = 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 Contact_1 = require("../model/Contact");
const Document_1 = require("../model/Document");
const Form_1 = require("../model/Form");
const HealthElement_1 = require("../model/HealthElement");
const IndexingInfo_1 = require("../model/IndexingInfo");
const Invoice_1 = require("../model/Invoice");
const Message_1 = require("../model/Message");
const Patient_1 = require("../model/Patient");
const ReplicationInfo_1 = require("../model/ReplicationInfo");
const ReplicatorDocument_1 = require("../model/ReplicatorDocument");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const Code_1 = require("../model/Code");
class IccIcureApi {
    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;
    }
    /**
     *
     * @summary Get index info
     */
    getIndexingInfo() {
        let _body = null;
        const _url = this.host + `/icure/i` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new IndexingInfo_1.IndexingInfo(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Get process info
     */
    getProcessInfo() {
        let _body = null;
        const _url = this.host + `/icure/p` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Get replication info
     */
    getReplicationInfo() {
        let _body = null;
        const _url = this.host + `/icure/r` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new ReplicationInfo_1.ReplicationInfo(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Get replication info
     * @param id
     */
    getReplicatorInfo(id) {
        let _body = null;
        const _url = this.host + `/icure/r/${encodeURIComponent(String(id))}` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new ReplicatorDocument_1.ReplicatorDocument(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Get user sync info
     */
    getUserSyncInfo() {
        let _body = null;
        const _url = this.host + `/icure/sync/user` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Get version
     */
    getVersion() {
        let _body = null;
        const _url = this.host + `/icure/v` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Check if a user exists
     */
    isReady() {
        const _url = this.host + `/icure/ok` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @param loglevel
     * @param _package
     */
    loglevel(loglevel, _package) {
        let _body = null;
        const _url = this.host +
            `/icure/loglevel/${encodeURIComponent(String(loglevel))}` +
            '?ts=' +
            new Date().getTime() +
            (_package ? '&_package=' + encodeURIComponent(String(_package)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Resolve contacts conflicts
     * @param limit
     */
    resolveContactsConflicts(limit) {
        let _body = null;
        const _url = this.host + `/icure/conflicts/contact` + '?ts=' + new Date().getTime() + (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new Contact_1.Contact(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary resolve documents conflicts
     * @param ids
     * @param limit
     */
    resolveDocumentsConflicts(ids, limit) {
        let _body = null;
        const _url = this.host +
            `/icure/conflicts/document` +
            '?ts=' +
            new Date().getTime() +
            (ids ? '&ids=' + encodeURIComponent(String(ids)) : '') +
            (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new Document_1.Document(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary resolve forms conflicts
     * @param limit
     */
    resolveFormsConflicts(limit) {
        let _body = null;
        const _url = this.host + `/icure/conflicts/form` + '?ts=' + new Date().getTime() + (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new Form_1.Form(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary resolve healthcare elements conflicts
     * @param limit
     */
    resolveHealthElementsConflicts(limit) {
        let _body = null;
        const _url = this.host + `/icure/conflicts/healthelement` + '?ts=' + new Date().getTime() + (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        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 resolve invoices conflicts
     * @param limit
     */
    resolveInvoicesConflicts(limit) {
        let _body = null;
        const _url = this.host + `/icure/conflicts/invoice` + '?ts=' + new Date().getTime() + (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new Invoice_1.Invoice(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary resolve messages conflicts
     * @param limit
     */
    resolveMessagesConflicts(limit) {
        let _body = null;
        const _url = this.host + `/icure/conflicts/message` + '?ts=' + new Date().getTime() + (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new Message_1.Message(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Resolve patients conflicts
     * @param limit
     */
    resolvePatientsConflicts(limit) {
        let _body = null;
        const _url = this.host + `/icure/conflicts/patient` + '?ts=' + new Date().getTime() + (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new Patient_1.Patient(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Resolve codes conflicts
     * @param limit
     */
    resolveCodesConflicts(limit) {
        let _body = null;
        const _url = this.host + `/icure/conflicts/code` + '?ts=' + new Date().getTime() + (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new Code_1.Code(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Force update design doc
     * @param entityName
     * @param warmup
     */
    updateDesignDoc(entityName, warmup) {
        const _url = this.host +
            `/icure/dd/${encodeURIComponent(String(entityName))}` +
            '?ts=' +
            new Date().getTime() +
            (warmup ? '&warmup=' + encodeURIComponent(String(warmup)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Gets the value of a property in the CouchDB configuration.
     * WARNING: this method only works with a local installation of CouchDB.
     * @param section the section of the configuration.
     * @param key the specific key to get the value.
     */
    getCouchDbConfigProperty(section, key) {
        const _url = this.host + `/icure/couchdb/config/${encodeURIComponent(section)}/${encodeURIComponent(key)}` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Sets the value of a property in the CouchDB configuration.
     * WARNING: this method only works with a local installation of CouchDB.
     * @param section the section of the configuration.
     * @param key the specific key to get the value.
     * @param value the value to set for the property.
     */
    setCouchDbConfigProperty(section, key, value) {
        const _url = this.host +
            `/icure/couchdb/config/${encodeURIComponent(section)}/${encodeURIComponent(key)}` +
            '?ts=' +
            new Date().getTime() +
            `&value=${encodeURIComponent(value)}`;
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('PUT', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Sets the value of a property in kraken. The current supported properties are:
     * - `useDataOwnerPartition` values: true/false
     * - `useObsoleteViews` values: true/false
     * WARNING: this method only works Kraken lite.
     * @param property the name of the property to set.
     * @param value the value to set for the property.
     */
    setLiteConfigProperty(property, value) {
        const _url = this.host + `/icure/lite/config/${encodeURIComponent(property)}/${encodeURIComponent(value)}` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('PUT', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
}
exports.IccIcureApi = IccIcureApi;
//# sourceMappingURL=IccIcureApi.js.map