"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.IccFormApi = 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 Form_1 = require("../model/Form");
const FormTemplate_1 = require("../model/FormTemplate");
const IcureStub_1 = require("../model/IcureStub");
const ListOfIds_1 = require("../model/ListOfIds");
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 IccFormApi {
    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 form.
     * @summary Create a form with the current user
     * @param body
     */
    createForm(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form` + '?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 Form_1.Form(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns an instance of created form template.
     * @summary Create a form template with the current user
     * @param body
     */
    createFormTemplate(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/template` + '?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 FormTemplate_1.FormTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the created forms.
     * @summary Create a batch of forms
     * @param body
     */
    createForms(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/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 Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Delete a form template
     * @param formTemplateId
     */
    deleteFormTemplate(formTemplateId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/form/template/${encodeURIComponent(String(formTemplateId))}` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('DELETE', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Delete forms by batch.
     *
     * @param formIds a ListOfIds containing the ids of the Forms to delete.
     * @return a Promise that will resolve in an array of DocIdentifiers related to the successfully deleted Forms.
     */
    deleteForms(formIds) {
        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 + `/form/delete/batch` + '?ts=' + new Date().getTime(), headers, formIds, 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 form by id.
     *
     * @param formId the id of the document to delete.
     * @return a Promise that will resolve in the DocIdentifier of the form.
     */
    deleteForm(formId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/form/${encodeURIComponent(formId)}` + '?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));
        });
    }
    /**
     *
     * @summary Gets all form templates for current user
     * @param loadLayout
     * @param raw
     */
    findFormTemplates(loadLayout, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template` +
                '?ts=' +
                new Date().getTime() +
                (loadLayout ? '&loadLayout=' + encodeURIComponent(String(loadLayout)) : '') +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            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 FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets all form templates
     * @param specialityCode
     * @param loadLayout
     */
    findFormTemplatesBySpeciality(specialityCode, loadLayout, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template/bySpecialty/${encodeURIComponent(String(specialityCode))}` +
                '?ts=' +
                new Date().getTime() +
                (loadLayout ? '&loadLayout=' + encodeURIComponent(String(loadLayout)) : '') +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            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 FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by coma
     * @deprecated use {@link findFormIdsByDataOwnerPatientOpeningDate} instead.
     * @summary List forms found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param healthElementId
     * @param planOfActionId
     * @param formTemplateId
     * @param body
     */
    findFormsByHCPartyPatientForeignKeysUsingPost(hcPartyId, healthElementId, planOfActionId, formTemplateId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/form/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (healthElementId ? '&healthElementId=' + encodeURIComponent(String(healthElementId)) : '') +
                (planOfActionId ? '&planOfActionId=' + encodeURIComponent(String(planOfActionId)) : '') +
                (formTemplateId ? '&formTemplateId=' + encodeURIComponent(String(formTemplateId)) : '');
            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 Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by commas.
     * @deprecated use {@link findFormIdsByDataOwnerPatientOpeningDate} instead.
     * @summary List forms found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     * @param healthElementId
     * @param planOfActionId
     * @param formTemplateId
     */
    findFormsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys, healthElementId, planOfActionId, formTemplateId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '') +
                (healthElementId ? '&healthElementId=' + encodeURIComponent(String(healthElementId)) : '') +
                (planOfActionId ? '&planOfActionId=' + encodeURIComponent(String(planOfActionId)) : '') +
                (formTemplateId ? '&formTemplateId=' + encodeURIComponent(String(formTemplateId)) : '');
            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 Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary List Form ids by data owner and a set of secret foreign key. The ids will be sorted by Form 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 form ids since the beginning of time will be returned.
     * @param endDate a timestamp in epoch milliseconds. If undefined, all the form ids until the end of time will be returned.
     * @param descending whether to return the ids ordered in ascending or descending order by Form openingDate
     * @return a promise that will resolve in an Array of Form ids.
     */
    findFormIdsByDataOwnerPatientOpeningDate(dataOwnerId, secretFKeys, startDate, endDate, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/form/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));
        });
    }
    /**
     * Keys must be delimited by coma
     * @deprecated use {@link findFormsDelegationsStubsByIds} instead.
     * @summary List form stubs found By Healthcare Party and secret foreign keys.
     * @param body
     * @param hcPartyId
     */
    findFormsDelegationsStubsByHCPartyPatientForeignKeysUsingPost(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/form/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));
        });
    }
    /**
     * @deprecated use {@link findFormsDelegationsStubsByIds} instead.
     * @summary List form stubs found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     */
    findFormsDelegationsStubsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/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));
        });
    }
    /**
     * @summary List form stubs by form ids.
     */
    findFormsDelegationsStubsByIds(formIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/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: formIds }, 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
     * @summary Get a list of forms by ids
     * @param formId
     * @param hcPartyId
     */
    getChildrenForms(formId, hcPartyId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/form/childrenOf/${encodeURIComponent(String(formId))}/${encodeURIComponent(String(hcPartyId))}` + '?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) => doc.body.map((it) => new Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets a form
     * @param formId
     */
    getForm(formId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/form/${encodeURIComponent(String(formId))}` + '?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 Form_1.Form(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets the most recent form with the given logicalUuid
     * @param logicalUuid
     */
    getFormByLogicalUuid(logicalUuid) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/form/logicalUuid/${encodeURIComponent(String(logicalUuid))}` + '?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 Form_1.Form(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets the most recent form with the given uniqueId
     * @param uniqueId
     */
    getFormByUniqueId(uniqueId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/form/uniqueId/${encodeURIComponent(String(uniqueId))}` + '?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 Form_1.Form(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets a form template by guid
     * @param formTemplateId
     * @param raw
     */
    getFormTemplate(formTemplateId, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template/${encodeURIComponent(String(formTemplateId))}` +
                '?ts=' +
                new Date().getTime() +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new FormTemplate_1.FormTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated This method behavior is not intuitive.
     * If there is any form template with author=currentUser and guid={@link formTemplateGuid} returns them, regardless of
     * {@link specialityCode}.
     * Else returns all form templates with specialty.code={@link specialityCode} and guid={@link formTemplateGuid}
     * regardless of the currentUser.
     */
    getFormTemplatesByGuid(formTemplateGuid, specialityCode, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template/${encodeURIComponent(String(specialityCode))}/guid/${encodeURIComponent(String(formTemplateGuid))}` +
                '?ts=' +
                new Date().getTime() +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            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 FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be delimited by coma
     * @summary Get a list of forms by ids
     * @param body
     */
    getForms(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/form/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 Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets all forms with given logicalUuid
     * @param logicalUuid
     */
    getFormsByLogicalUuid(logicalUuid) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/form/all/logicalUuid/${encodeURIComponent(String(logicalUuid))}` + '?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) => doc.body.map((it) => new Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets all forms by uniqueId
     * @param uniqueId
     */
    getFormsByUniqueId(uniqueId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/form/all/uniqueId/${encodeURIComponent(String(uniqueId))}` + '?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) => doc.body.map((it) => new Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified form.
     * @summary Modify a form
     * @param body
     */
    modifyForm(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/form` + '?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 Form_1.Form(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified forms.
     * @summary Modify a batch of forms
     * @param body
     */
    modifyForms(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/form/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 Form_1.Form(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Update a form template's layout
     * @param attachment
     * @param formTemplateId
     */
    setTemplateAttachmentMulti(attachment, formTemplateId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            if (attachment && !_body) {
                const parts = Array.isArray(attachment) ? attachment : [attachment];
                const _blob = new Blob(parts, { type: 'application/octet-stream' });
                _body = new FormData();
                _body.append('attachment', _blob);
            }
            const _url = this.host + `/form/template/${encodeURIComponent(String(formTemplateId))}/attachment/multipart` + '?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', 'multipart/form-data'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => JSON.parse(JSON.stringify(doc.body)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns an instance of created form template.
     * @summary Modify a form template with the current user
     * @param body
     * @param formTemplateId
     */
    updateFormTemplate(formTemplateId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/form/template/${encodeURIComponent(String(formTemplateId))}` + '?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 FormTemplate_1.FormTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of form templates for the specified user in a group.
     * @summary Get form templates by user in a group
     * @param groupId the id of the group
     * @param userId the id of the user
     * @param loadLayout whether to load the layout of the form templates
     * @param raw whether to use raw mapping for the form templates
     */
    getFormTemplatesByUserInGroup(groupId, userId, loadLayout, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}/byUser/${encodeURIComponent(String(userId))}` +
                '?ts=' +
                new Date().getTime() +
                (loadLayout !== undefined ? '&loadLayout=' + encodeURIComponent(String(loadLayout)) : '') +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            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 FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of form templates for the specified specialty in a group.
     * @summary Get form templates by specialty in a group
     * @param groupId the id of the group
     * @param specialityCode the specialty code to filter templates by
     * @param loadLayout whether to load the layout of the form templates
     * @param raw whether to use raw mapping for the form templates
     */
    getFormTemplatesBySpecialtyInGroup(groupId, specialityCode, loadLayout, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}/bySpecialty/${encodeURIComponent(String(specialityCode))}` +
                '?ts=' +
                new Date().getTime() +
                (loadLayout !== undefined ? '&loadLayout=' + encodeURIComponent(String(loadLayout)) : '') +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            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 FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns an instance of created form template.
     * @summary Create a form template in a group
     * @param groupId the id of the group
     * @param body the form template to create
     */
    createFormTemplateInGroup(groupId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/template/inGroup/${encodeURIComponent(String(groupId))}` + '?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 FormTemplate_1.FormTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Delete a form template in a group
     * @param groupId the id of the group
     * @param formTemplateId the id of the form template to delete
     * @param rev the revision of the form template to delete
     */
    deleteFormTemplateInGroup(groupId, formTemplateId, rev) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}/${encodeURIComponent(String(formTemplateId))}?rev=${encodeURIComponent(String(rev))}` +
                '&ts=' +
                new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('DELETE', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns an instance of modified form template.
     * @summary Modify a form template in a group
     * @param groupId the id of the group
     * @param formTemplateId the id of the form template to modify
     * @param body the form template with updated data
     */
    updateFormTemplateInGroup(groupId, formTemplateId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}` +
                '?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 FormTemplate_1.FormTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Update a form template's layout in a group using multipart upload
     * @param groupId the id of the group
     * @param attachment the layout data
     * @param formTemplateId the id of the form template
     */
    setTemplateAttachmentMultiInGroup(groupId, attachment, formTemplateId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            if (attachment && !_body) {
                const parts = Array.isArray(attachment) ? attachment : [attachment];
                const _blob = new Blob(parts, { type: 'application/octet-stream' });
                _body = new FormData();
                _body.append('attachment', _blob);
            }
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}/${encodeURIComponent(String(formTemplateId))}/attachment/multipart` +
                '?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', 'multipart/form-data'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => JSON.parse(JSON.stringify(doc.body)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Update a form template's layout in a group
     * @param groupId the id of the group
     * @param formTemplateId the id of the form template
     * @param payload the layout data as binary
     */
    setTemplateAttachmentInGroup(groupId, formTemplateId, payload) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}/${encodeURIComponent(String(formTemplateId))}/attachment` +
                '?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/octet-stream'));
            return XHR_1.XHR.sendCommand('PUT', _url, headers, payload, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => JSON.parse(JSON.stringify(doc.body)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Create a batch of form templates in a group
     * @param groupId the id of the group
     * @param formTemplates the form templates to create
     */
    createFormTemplatesInGroup(groupId, formTemplates) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/template/inGroup/${encodeURIComponent(String(groupId))}/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, formTemplates, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Modify a batch of form templates in a group
     * @param groupId the id of the group
     * @param formTemplates the form templates to modify
     */
    modifyFormTemplatesInGroup(groupId, formTemplates) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/template/inGroup/${encodeURIComponent(String(groupId))}/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, formTemplates, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Get form templates in a group by their ids
     * @param groupId the id of the group
     * @param formTemplateIds the list of form template ids
     * @param raw whether to use raw mapping for the form templates
     */
    getFormTemplatesInGroup(groupId, formTemplateIds, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}/byIds` +
                '?ts=' +
                new Date().getTime() +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            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: formTemplateIds }, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Get a form template in a group
     * @param groupId the id of the group
     * @param formTemplateId the id of the form template
     * @param raw whether to use raw mapping for the form template
     */
    getFormTemplateInGroup(groupId, formTemplateId, raw) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/form/template/inGroup/${encodeURIComponent(String(groupId))}/${encodeURIComponent(String(formTemplateId))}` +
                '?ts=' +
                new Date().getTime() +
                (raw ? '&raw=' + encodeURIComponent(String(raw)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new FormTemplate_1.FormTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Delete a batch of form templates in a group
     * @param groupId the id of the group
     * @param formTemplateIdsAndRevs the list of form template ids and revisions
     */
    deleteFormTemplatesInGroup(groupId, formTemplateIdsAndRevs) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/template/inGroup/${encodeURIComponent(String(groupId))}/delete/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, { ids: formTemplateIdsAndRevs }, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new DocIdentifier_1.DocIdentifier(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Undelete a batch of form templates in a group
     * @param groupId the id of the group
     * @param formTemplateIdsAndRevs the list of form template ids and revisions
     */
    undeleteFormTemplatesInGroup(groupId, formTemplateIdsAndRevs) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/template/inGroup/${encodeURIComponent(String(groupId))}/undelete/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, { ids: formTemplateIdsAndRevs }, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new FormTemplate_1.FormTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Purge a batch of form templates in a group
     * @param groupId the id of the group
     * @param formTemplateIdsAndRevs the list of form template ids and revisions
     */
    purgeFormTemplatesInGroup(groupId, formTemplateIdsAndRevs) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/form/template/inGroup/${encodeURIComponent(String(groupId))}/purge/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, { ids: formTemplateIdsAndRevs }, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new DocIdentifier_1.DocIdentifier(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareForms(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/form/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, Form_1.Form)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareFormsMinimal(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/form/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.IccFormApi = IccFormApi;
//# sourceMappingURL=IccFormApi.js.map