"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccBeresultimportApi = 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 ResultInfo_1 = require("../model/ResultInfo");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccBeresultimportApi {
    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 Can we handle this document
     * @param id
     * @param enckeys
     */
    canHandle(id, enckeys) {
        let _body = null;
        const _url = this.host +
            `/be_result_import/canhandle/${encodeURIComponent(String(id))}` +
            '?ts=' +
            new Date().getTime() +
            (enckeys ? '&enckeys=' + encodeURIComponent(String(enckeys)) : '');
        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 import document
     * @param documentId
     * @param hcpId
     * @param language
     * @param protocolIds
     * @param formIds
     * @param planOfActionId
     * @param enckeys
     * @param ctc
     */
    doImport(documentId, hcpId, language, protocolIds, formIds, planOfActionId, enckeys, ctc) {
        let _body = null;
        _body = ctc;
        const _url = this.host +
            `/be_result_import/import/${encodeURIComponent(String(documentId))}/${encodeURIComponent(String(hcpId))}/${encodeURIComponent(String(language))}` +
            '?ts=' +
            new Date().getTime() +
            (protocolIds ? '&protocolIds=' + encodeURIComponent(String(protocolIds)) : '') +
            (formIds ? '&formIds=' + encodeURIComponent(String(formIds)) : '') +
            (planOfActionId ? '&planOfActionId=' + encodeURIComponent(String(planOfActionId)) : '') +
            (enckeys ? '&enckeys=' + encodeURIComponent(String(enckeys)) : '');
        const 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, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new Contact_1.Contact(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Extract general infos from document
     * @param id
     * @param language
     * @param enckeys
     * @param full
     */
    getInfos(id, language, enckeys, full) {
        let _body = null;
        const _url = this.host +
            `/be_result_import/infos/${encodeURIComponent(String(id))}` +
            '?ts=' +
            new Date().getTime() +
            (language ? '&language=' + encodeURIComponent(String(language)) : '') +
            (enckeys ? '&enckeys=' + encodeURIComponent(String(enckeys)) : '') +
            (full ? '&full=' + encodeURIComponent(String(full)) : '');
        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 ResultInfo_1.ResultInfo(it)))
            .catch((err) => this.handleError(err));
    }
}
exports.IccBeresultimportApi = IccBeresultimportApi;
//# sourceMappingURL=IccBeresultimportApi.js.map