"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.IccEntitytemplateApi = 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 EntityTemplate_1 = require("../model/EntityTemplate");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccEntitytemplateApi {
    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;
    }
    /**
     * Type, EntityTemplate and Version are required.
     * @summary Create a EntityTemplate
     * @param body
     */
    createEntityTemplate(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/entitytemplate` + '?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 EntityTemplate_1.EntityTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified entityTemplates.
     * @summary Create a batch of entityTemplates
     * @param body
     */
    createEntityTemplates(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/entitytemplate/batch` + '?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) => doc.body.map((it) => new EntityTemplate_1.EntityTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a batch of entity templates.
     *
     * @param entityTemplateIds a ListOfIds containing the ids of the entity templates to delete.
     * @return a Promise that will resolve in an array of DocIdentifiers of the successfully deleted entity templates.
     */
    deleteEntityTemplates(entityTemplateIds) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('POST', this.host + `/entitytemplate/delete/batch` + '?ts=' + new Date().getTime(), this.headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json')), entityTemplateIds, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new DocIdentifier_1.DocIdentifier(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of entityTemplates matched with given input.
     * @summary Finding entityTemplates by entityTemplate, type and version with pagination.
     * @param type
     * @param searchString
     * @param includeEntities
     */
    findAllEntityTemplates(type, searchString, includeEntities) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/entitytemplate/findAll/${encodeURIComponent(String(type))}` +
                '?ts=' +
                new Date().getTime() +
                (searchString ? '&searchString=' + encodeURIComponent(String(searchString)) : '') +
                (includeEntities ? '&includeEntities=' + encodeURIComponent(String(includeEntities)) : '');
            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 EntityTemplate_1.EntityTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of entityTemplates matched with given input.
     * @summary Finding entityTemplates by entityTemplate, type and version with pagination.
     * @param type
     * @param keyword
     * @param includeEntities
     */
    findAllEntityTemplatesByKeyword(type, keyword, includeEntities) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/entitytemplate/findAll/${encodeURIComponent(String(type))}/keyword/${encodeURIComponent(String(keyword))}` +
                '?ts=' +
                new Date().getTime() +
                (includeEntities ? '&includeEntities=' + encodeURIComponent(String(includeEntities)) : '');
            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 EntityTemplate_1.EntityTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of entityTemplates matched with given input.
     * @summary Finding entityTemplates by userId, entityTemplate, type and version with pagination.
     * @param userId
     * @param type
     * @param searchString
     * @param includeEntities
     */
    findEntityTemplates(userId, type, searchString, includeEntities) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/entitytemplate/find/${encodeURIComponent(String(userId))}/${encodeURIComponent(String(type))}` +
                '?ts=' +
                new Date().getTime() +
                (searchString ? '&searchString=' + encodeURIComponent(String(searchString)) : '') +
                (includeEntities ? '&includeEntities=' + encodeURIComponent(String(includeEntities)) : '');
            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 EntityTemplate_1.EntityTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of entityTemplates matched with given input.
     * @summary Finding entityTemplates by userId, type and keyword.
     * @param userId
     * @param type
     * @param keyword
     * @param includeEntities
     */
    findEntityTemplatesByKeyword(userId, type, keyword, includeEntities) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/entitytemplate/find/${encodeURIComponent(String(userId))}/${encodeURIComponent(String(type))}/keyword/${encodeURIComponent(String(keyword))}` +
                '?ts=' +
                new Date().getTime() +
                (includeEntities ? '&includeEntities=' + encodeURIComponent(String(includeEntities)) : '');
            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 EntityTemplate_1.EntityTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Get a entityTemplate based on ID or (entityTemplate,type,version) as query strings. (entityTemplate,type,version) is unique.
     * @summary Get a entityTemplate
     * @param entityTemplateId EntityTemplate id
     */
    getEntityTemplate(entityTemplateId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/entitytemplate/${encodeURIComponent(String(entityTemplateId))}` + '?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 EntityTemplate_1.EntityTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Keys must be a list of entity template ids
     * @summary Get a list of entityTemplates by ids
     * @param entityTemplateIds
     */
    getEntityTemplates(entityTemplateIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/entitytemplate/byIds` + '?ts=' + new Date().getTime();
            let headers = this.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, entityTemplateIds, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new EntityTemplate_1.EntityTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Modification of (type, entityTemplate, version) is not allowed.
     * @summary Modify a entityTemplate
     * @param body
     */
    modifyEntityTemplate(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/entitytemplate` + '?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 EntityTemplate_1.EntityTemplate(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified entityTemplates.
     * @summary Modify a batch of entityTemplates
     * @param body
     */
    modifyEntityTemplates(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/entitytemplate/batch` + '?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) => doc.body.map((it) => new EntityTemplate_1.EntityTemplate(it)))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccEntitytemplateApi = IccEntitytemplateApi;
//# sourceMappingURL=IccEntitytemplateApi.js.map