"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.IccInsuranceApi = 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 ListOfIds_1 = require("../model/ListOfIds");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const PaginatedListInsurance_1 = require("../model/PaginatedListInsurance");
const Insurance_1 = require("../model/Insurance");
class IccInsuranceApi {
    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 Creates an insurance
     * @param body
     */
    createInsurance(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/insurance` + '?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 Insurance_1.Insurance(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Deletes an insurance
     * @param insuranceId
     */
    deleteInsurance(insuranceId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/insurance/${encodeURIComponent(insuranceId)}` + '?ts=' + new Date().getTime();
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('DELETE', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets an insurance
     * @param insuranceId
     */
    getInsurance(insuranceId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/insurance/${encodeURIComponent(String(insuranceId))}` + '?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 Insurance_1.Insurance(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets insurances by id
     * @param body
     */
    getInsurances(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/insurance/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 Insurance_1.Insurance(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets an insurance
     * @param insuranceCode
     */
    listInsurancesByCode(insuranceCode) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/insurance/byCode/${encodeURIComponent(String(insuranceCode))}` + '?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 Insurance_1.Insurance(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets an insurance
     * @param insuranceName
     */
    listInsurancesByName(insuranceName) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/insurance/byName/${encodeURIComponent(String(insuranceName))}` + '?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 Insurance_1.Insurance(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Modifies an insurance
     * @param body
     */
    modifyInsurance(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/insurance` + '?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 Insurance_1.Insurance(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    getAllInsurances(startDocumentId, limit) {
        let _body = null;
        const _url = this.host +
            `/insurance?ts=` +
            new Date().getTime() +
            (!!startDocumentId ? `&startDocumentId=${encodeURIComponent(startDocumentId)}` : '') +
            (!!limit ? `&limit=${encodeURIComponent(limit)}` : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new PaginatedListInsurance_1.PaginatedListInsurance(doc.body))
            .catch((err) => this.handleError(err));
    }
    modifyInsurancesInGroup(groupId, insurances) {
        let _body = null;
        _body = insurances;
        const _url = this.host + `/insurance/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 Insurance_1.Insurance(it)))
            .catch((err) => this.handleError(err));
    }
    createInsurancesInGroup(groupId, insurances) {
        let _body = null;
        _body = insurances;
        const _url = this.host + `/insurance/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 Insurance_1.Insurance(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a list of insurances by ids/keys.
     * @summary Gets a list of insurances by ids
     * @param insuranceIds
     */
    getInsurancesInGroup(groupId, insuranceIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const body = new ListOfIds_1.ListOfIds({ ids: insuranceIds });
            const _url = this.host + `/insurance/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 Insurance_1.Insurance(it)))
                .catch((err) => this.handleError(err));
        });
    }
    matchInsurancesByInGroup(groupId_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (groupId, body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host + `/insurance/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.IccInsuranceApi = IccInsuranceApi;
//# sourceMappingURL=IccInsuranceApi.js.map