"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.IccCodeApi = 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 Code_1 = require("../model/Code");
const PaginatedListCode_1 = require("../model/PaginatedListCode");
const Unit_1 = require("../model/Unit");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const ListOfIds_1 = require("../model/ListOfIds");
class IccCodeApi {
    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;
    }
    /**
     * Create a code entity. Fields Type, Code and Version are required.
     * @summary Create a code
     * @param body
     */
    createCode(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/code` + '?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 Code_1.Code(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Create a batch of code entities. Fields Type, Code and Version are required for each code.
     * @summary Create a batch of codes
     * @param body
     */
    createCodes(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/code/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 Code_1.Code(it)))
            .catch((err) => this.handleError(err));
    }
    filterCodesBy(startKey, startDocumentId, limit, skip, sort, desc, body, collectTiming = false) {
        let _body = null;
        _body = body;
        const _url = this.host +
            `/code/filter` +
            '?ts=' +
            new Date().getTime() +
            (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
            (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
            (limit ? '&limit=' + encodeURIComponent(String(limit)) : '') +
            (skip ? '&skip=' + encodeURIComponent(String(skip)) : '') +
            (sort ? '&sort=' + encodeURIComponent(String(sort)) : '') +
            (desc ? '&desc=' + encodeURIComponent(String(desc)) : '');
        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(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
            .then((doc) => Object.assign(new PaginatedListCode_1.PaginatedListCode(doc.body), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of code types matched with given input.
     * @summary Get list of code types by region and type.
     * @param region Code region
     * @param type Code type
     */
    findCodeTypes(region, type) {
        let _body = null;
        const _url = this.host +
            `/code/codetype/byRegionType` +
            '?ts=' +
            new Date().getTime() +
            (region ? '&region=' + encodeURIComponent(String(region)) : '') +
            (type ? '&type=' + encodeURIComponent(String(type)) : '');
        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) => JSON.parse(JSON.stringify(it))))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of codes matched with given input.
     * @summary Gets list of codes by code, type and version
     * @param region Code region
     * @param type Code type
     * @param code Code code
     * @param version Code version
     */
    findCodes(region, type, code, version) {
        let _body = null;
        const _url = this.host +
            `/code/byRegionTypeCode` +
            '?ts=' +
            new Date().getTime() +
            (region ? '&region=' + encodeURIComponent(String(region)) : '') +
            (type ? '&type=' + encodeURIComponent(String(type)) : '') +
            (code ? '&code=' + encodeURIComponent(String(code)) : '') +
            (version ? '&version=' + encodeURIComponent(String(version)) : '');
        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 Code_1.Code(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of codes matched with given input.
     * @summary Gets paginated list of codes by code, type and version.
     * @param region
     * @param type
     * @param code
     * @param version
     * @param startKey The start key for pagination
     * @param startDocumentId A code document ID
     * @param limit Number of rows
     */
    findPaginatedCodes(region, type, code, version, startKey, startDocumentId, limit) {
        let _body = null;
        const _url = this.host +
            `/code` +
            '?ts=' +
            new Date().getTime() +
            (region ? '&region=' + encodeURIComponent(String(region)) : '') +
            (type ? '&type=' + encodeURIComponent(String(type)) : '') +
            (code ? '&code=' + encodeURIComponent(String(code)) : '') +
            (version ? '&version=' + encodeURIComponent(String(version)) : '') +
            (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 PaginatedListCode_1.PaginatedListCode(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of codes matched with given input. If several types are provided, pagination is not supported
     * @summary Get paginated list of codes by code, type and version.
     * @param region
     * @param types
     * @param language
     * @param label
     * @param version
     * @param startKey The start key for pagination: a JSON representation of an array containing all the necessary components to form the Complex Key&#x27;s startKey
     * @param startDocumentId A code document ID
     * @param limit Number of rows
     */
    findPaginatedCodesByLabel(region, types, language, label, version, startKey, startDocumentId, limit) {
        let _body = null;
        const _url = this.host +
            `/code/byLabel` +
            '?ts=' +
            new Date().getTime() +
            (region ? '&region=' + encodeURIComponent(String(region)) : '') +
            (types ? '&types=' + encodeURIComponent(String(types)) : '') +
            (language ? '&language=' + encodeURIComponent(String(language)) : '') +
            (label ? '&label=' + encodeURIComponent(String(label)) : '') +
            (version ? '&version=' + encodeURIComponent(String(version)) : '') +
            (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 PaginatedListCode_1.PaginatedListCode(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of codes matched with given input.
     * @summary Gets paginated list of codes by link and link type.
     * @param linkType
     * @param linkedId
     * @param startKey The start key for pagination: a JSON representation of an array containing all the necessary components to form the Complex Key&#x27;s startKey
     * @param startDocumentId A code document ID
     * @param limit Number of rows
     */
    findPaginatedCodesWithLink(linkType, linkedId, startKey, startDocumentId, limit) {
        let _body = null;
        const _url = this.host +
            `/code/byLink/${encodeURIComponent(String(linkType))}` +
            '?ts=' +
            new Date().getTime() +
            (linkedId ? '&linkedId=' + encodeURIComponent(String(linkedId)) : '') +
            (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 PaginatedListCode_1.PaginatedListCode(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of tag types matched with given input.
     * @summary Gets list of tag types by region and type.
     * @param region Code region
     * @param type Code type
     */
    findTagTypes(region, type) {
        let _body = null;
        const _url = this.host +
            `/code/tagtype/byRegionType` +
            '?ts=' +
            new Date().getTime() +
            (region ? '&region=' + encodeURIComponent(String(region)) : '') +
            (type ? '&type=' + encodeURIComponent(String(type)) : '');
        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) => JSON.parse(JSON.stringify(it))))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a code based on its id
     * @summary Get a code by id
     * @param codeId Code id
     */
    getCode(codeId) {
        let _body = null;
        const _url = this.host + `/code/${encodeURIComponent(String(codeId))}` + '?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 Code_1.Code(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a code based on (type, code, version) as query strings. (type, code, version) is unique.
     * @summary Get a code
     * @param type Code type
     * @param code Code code
     * @param version Code version
     */
    getCodeWithParts(type, code, version) {
        let _body = null;
        const _url = this.host +
            `/code/${encodeURIComponent(String(type))}/${encodeURIComponent(String(code))}/${encodeURIComponent(String(version))}` +
            '?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 Code_1.Code(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a list of codes by ids/keys.
     * @summary Gets a list of codes by ids
     * @param codeIds
     */
    getCodes(codeIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const body = new ListOfIds_1.ListOfIds({ ids: codeIds });
            const _url = this.host + `/code/byIds` + '?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 Code_1.Code(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Import codes from the resources XML file depending on the passed pathVariable
     * @summary Import codes
     * @param codeType
     */
    importCodes(codeType) {
        let _body = null;
        const _url = this.host + `/code/${encodeURIComponent(String(codeType))}` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new Unit_1.Unit(doc.body))
            .catch((err) => this.handleError(err));
    }
    matchCodesBy(body, collectTiming = false) {
        let _body = null;
        _body = body;
        const _url = this.host + `/code/match` + '?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(), 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));
    }
    /**
     * Modification of (type, code, version) is not allowed.
     * @summary Modify a code
     * @param body
     */
    modifyCode(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/code` + '?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 Code_1.Code(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Modification of (type, code, version) is not allowed.
     * @summary Modify a batch of codes
     * @param body
     */
    modifyCodes(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/code/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 Code_1.Code(it)))
            .catch((err) => this.handleError(err));
    }
    modifyCodesInGroup(groupId, codes) {
        let _body = null;
        _body = codes;
        const _url = this.host + `/code/inGroup/${encodeURIComponent(String(groupId))}/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 Code_1.Code(it)))
            .catch((err) => this.handleError(err));
    }
    createCodesInGroup(groupId, codes) {
        let _body = null;
        _body = codes;
        const _url = this.host + `/code/inGroup/${encodeURIComponent(String(groupId))}/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 Code_1.Code(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a list of codes by ids/keys.
     * @summary Gets a list of codes by ids
     * @param codeIds
     */
    getCodesInGroup(groupId, codeIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const body = new ListOfIds_1.ListOfIds({ ids: codeIds });
            const _url = this.host + `/code/inGroup/${encodeURIComponent(String(groupId))}/byIds` + '?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 Code_1.Code(it)))
                .catch((err) => this.handleError(err));
        });
    }
    matchCodesByInGroup(groupId_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (groupId, body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host + `/code/inGroup/${encodeURIComponent(String(groupId))}/match` + '?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(), 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));
        });
    }
}
exports.IccCodeApi = IccCodeApi;
//# sourceMappingURL=IccCodeApi.js.map