"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.IccClassificationTemplateApi = 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 ClassificationTemplate_1 = require("../model/ClassificationTemplate");
const DocIdentifier_1 = require("../model/DocIdentifier");
const PaginatedListClassificationTemplate_1 = require("../model/PaginatedListClassificationTemplate");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccClassificationTemplateApi {
    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 classification Template.
     * @summary Create a classification Template with the current user
     * @param body
     */
    createClassificationTemplate(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/classificationTemplate` + '?ts=' + new Date().getTime();
            let headers = 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 ClassificationTemplate_1.ClassificationTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a batch of classification templates.
     *
     * @param classificationTemplateIds a ListOfIds containing the ids of the classification templates to delete.
     * @return a Promise that will resolve in an array of DocIdentifiers of the successfully deleted classification templates
     */
    deleteClassificationTemplates(classificationTemplateIds) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('POST', this.host + `/classificationTemplate/delete/batch` + '?ts=' + new Date().getTime(), this.headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json')), classificationTemplateIds, 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 classification template by id.
     *
     * @param classificationTemplateId the id of the classification template to delete.
     * @return a Promise that will resolve in the DocIdentifier of the deleted classification template.
     */
    deleteClassificationTemplate(classificationTemplateId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/classificationTemplate/${encodeURIComponent(classificationTemplateId)}` + '?ts=' + new Date().getTime(), this.headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys have to be delimited by commas.
     * @summary List classification Templates found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     */
    findClassificationTemplatesByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/classificationTemplate/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '');
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new ClassificationTemplate_1.ClassificationTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary List classification Templates found By Healthcare Party and a single secret foreign key with pagination.
     * @param hcPartyId the healthcare party id.
     * @param secretFKey the secret foreign key.
     * @param startKey the startKey provided by the previous page or undefined for the first page.
     * @param startDocumentId the startDocumentId provided by the previous page or undefined for the first page.
     * @param limit the number of elements that the page should contain.
     * @return a promise that will resolve in a PaginatedListClassificationTemplate.
     */
    findClassificationTemplatesByHCPartyPatientForeignKey(hcPartyId, secretFKey, startKey, startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/classificationTemplate/byHcPartySecretForeignKey?ts=${new Date().getTime()}` +
                `&hcPartyId=${encodeURIComponent(hcPartyId)}` +
                `&secretFKey=${encodeURIComponent(secretFKey)}` +
                (!!startKey ? `&startKey=${encodeURIComponent(startKey)}` : '') +
                (!!startDocumentId ? `&startDocumentId=${encodeURIComponent(startDocumentId)}` : '') +
                (!!limit ? `&limit=${limit}` : '');
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListClassificationTemplate_1.PaginatedListClassificationTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get a classification Template
     * @param classificationTemplateId
     */
    getClassificationTemplate(classificationTemplateId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/classificationTemplate/${encodeURIComponent(String(classificationTemplateId))}` + '?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 ClassificationTemplate_1.ClassificationTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Ids are seperated by a coma
     * @summary Get a list of classifications Templates
     * @param ids
     */
    getClassificationTemplateByIds(ids) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/classificationTemplate/byIds/${encodeURIComponent(String(ids))}` + '?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) => doc.body.map((it) => new ClassificationTemplate_1.ClassificationTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of classification templates.
     * @summary List all classification templates with pagination
     * @param startKey A label
     * @param startDocumentId An classification template document ID
     * @param limit Number of rows
     */
    listClassificationTemplates(startKey, startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/classificationTemplate` +
                '?ts=' +
                new Date().getTime() +
                (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListClassificationTemplate_1.PaginatedListClassificationTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified classification Template.
     * @summary Modify a classification Template
     * @param body
     */
    modifyClassificationTemplate(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/classificationTemplate` + '?ts=' + new Date().getTime();
            let headers = 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 ClassificationTemplate_1.ClassificationTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * It delegates a classification Template to a healthcare party (By current healthcare party). Returns the element with new delegations.
     * @summary Delegates a classification Template to a healthcare party
     * @param body
     * @param classificationTemplateId
     */
    newClassificationTemplateDelegations(classificationTemplateId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/classificationTemplate/${encodeURIComponent(String(classificationTemplateId))}/delegate` + '?ts=' + new Date().getTime();
            let headers = 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 ClassificationTemplate_1.ClassificationTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccClassificationTemplateApi = IccClassificationTemplateApi;
//# sourceMappingURL=IccClassificationTemplateApi.js.map