"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.IccTarificationApi = 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 ListOfIds_1 = require("../model/ListOfIds");
const PaginatedListTarification_1 = require("../model/PaginatedListTarification");
const Tarification_1 = require("../model/Tarification");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccTarificationApi {
    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, Tarification and Version are required.
     * @summary Create a Tarification
     * @param body
     */
    createTarification(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/tarification` + '?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 Tarification_1.Tarification(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of tarifications matched with given input.
     * @summary Finding tarifications by tarification, type and version with pagination.
     * @param region
     * @param type
     * @param tarification
     * @param version
     * @param startDocumentId A tarification document ID
     * @param startKey
     * @param limit Number of rows
     */
    findPaginatedTarifications(region, type, tarification, version, startDocumentId, startKey, limit) {
        let _body = null;
        const _url = this.host +
            `/tarification` +
            '?ts=' +
            new Date().getTime() +
            (region ? '&region=' + encodeURIComponent(String(region)) : '') +
            (type ? '&type=' + encodeURIComponent(String(type)) : '') +
            (tarification ? '&tarification=' + encodeURIComponent(String(tarification)) : '') +
            (version ? '&version=' + encodeURIComponent(String(version)) : '') +
            (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
            (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
            (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 PaginatedListTarification_1.PaginatedListTarification(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of tarifications matched with given input.
     * @summary Finding tarifications by tarification, type and version with pagination.
     * @param region
     * @param types
     * @param language
     * @param label
     * @param startKey
     * @param startDocumentId A tarification document ID
     * @param limit Number of rows
     */
    findPaginatedTarificationsByLabel(region, types, language, label, startKey, startDocumentId, limit) {
        let _body = null;
        const _url = this.host +
            `/tarification/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)) : '') +
            (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 PaginatedListTarification_1.PaginatedListTarification(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * @deprecated Replace with `findPaginatedTarifications` (same but paginated)
     */
    findTarifications(region, type, tarification, version) {
        let _body = null;
        const _url = this.host +
            `/tarification/byRegionTypeTarification` +
            '?ts=' +
            new Date().getTime() +
            (region ? '&region=' + encodeURIComponent(String(region)) : '') +
            (type ? '&type=' + encodeURIComponent(String(type)) : '') +
            (tarification ? '&tarification=' + encodeURIComponent(String(tarification)) : '') +
            (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 Tarification_1.Tarification(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a tarification based on ID or (tarification,type,version) as query strings. (tarification,type,version) is unique.
     * @summary Get a tarification
     * @param tarificationId Tarification id
     */
    getTarification(tarificationId) {
        let _body = null;
        const _url = this.host + `/tarification/${encodeURIComponent(String(tarificationId))}` + '?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 Tarification_1.Tarification(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a tarification based on ID or (tarification,type,version) as query strings. (tarification,type,version) is unique.
     * @summary Get a tarification
     * @param type Tarification type
     * @param tarification Tarification tarification
     * @param version Tarification version
     */
    getTarificationWithParts(type, tarification, version) {
        let _body = null;
        const _url = this.host +
            `/tarification/${encodeURIComponent(String(type))}/${encodeURIComponent(String(tarification))}/${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 Tarification_1.Tarification(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Keys must be delimited by coma
     * @summary Get a list of tarifications by ids
     * @param body
     */
    getTarifications(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/tarification/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 Tarification_1.Tarification(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Modification of (type, tarification, version) is not allowed.
     * @summary Modify a tarification
     * @param body
     */
    modifyTarification(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/tarification` + '?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 Tarification_1.Tarification(doc.body))
            .catch((err) => this.handleError(err));
    }
    modifyTarificationsInGroup(groupId, tarifications) {
        let _body = null;
        _body = tarifications;
        const _url = this.host + `/tarification/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 Tarification_1.Tarification(it)))
            .catch((err) => this.handleError(err));
    }
    createTarificationsInGroup(groupId, tarifications) {
        let _body = null;
        _body = tarifications;
        const _url = this.host + `/tarification/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 Tarification_1.Tarification(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get a list of tarifications by ids/keys.
     * @summary Gets a list of tarifications by ids
     * @param tarificationIds
     */
    getTarificationsInGroup(groupId, tarificationIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const body = new ListOfIds_1.ListOfIds({ ids: tarificationIds });
            const _url = this.host + `/tarification/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 Tarification_1.Tarification(it)))
                .catch((err) => this.handleError(err));
        });
    }
    matchTarificationsByInGroup(groupId_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (groupId, body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host + `/tarification/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.IccTarificationApi = IccTarificationApi;
//# sourceMappingURL=IccTarificationApi.js.map