"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccBeefactApi = 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 MessageWithBatch_1 = require("../model/MessageWithBatch");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccBeefactApi {
    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 create batch and message
     * @param body
     * @param insuranceId
     * @param newMessageId
     * @param numericalRef
     */
    createBatchAndMessage(insuranceId, newMessageId, numericalRef, body) {
        let _body = null;
        _body = body;
        const _url = this.host +
            `/be_efact/${encodeURIComponent(String(insuranceId))}/${encodeURIComponent(String(newMessageId))}/${encodeURIComponent(String(numericalRef))}` +
            '?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 MessageWithBatch_1.MessageWithBatch(doc.body))
            .catch((err) => this.handleError(err));
    }
}
exports.IccBeefactApi = IccBeefactApi;
//# sourceMappingURL=IccBeefactApi.js.map