"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.IccApplicationsettingsApi = 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 ApplicationSettings_1 = require("../model/ApplicationSettings");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const EntityBulkShareResult_1 = require("../model/requests/EntityBulkShareResult");
const MinimalEntityBulkShareResult_1 = require("../model/requests/MinimalEntityBulkShareResult");
class IccApplicationsettingsApi {
    get headers() {
        return Promise.resolve(this._headers);
    }
    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 new application settings
     * @param body
     */
    createApplicationSettings(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/appsettings` + '?ts=' + new Date().getTime();
            let headers = yield 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 ApplicationSettings_1.ApplicationSettings(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets all application settings
     */
    getApplicationSettings() {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/appsettings` + '?ts=' + new Date().getTime();
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new ApplicationSettings_1.ApplicationSettings(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Update application settings
     * @param body
     */
    updateApplicationSettings(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/appsettings` + '?ts=' + new Date().getTime();
            let headers = yield 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 ApplicationSettings_1.ApplicationSettings(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareApplicationSettings(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/appsettings/bulkSharedMetadataUpdate' + '?ts=' + new Date().getTime();
            let headers = yield 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, request, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((x) => new EntityBulkShareResult_1.EntityBulkShareResult(x, ApplicationSettings_1.ApplicationSettings)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareApplicationSettingsMinimal(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/appsettings/bulkSharedMetadataUpdateMinimal' + '?ts=' + new Date().getTime();
            let headers = yield 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, request, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((x) => new MinimalEntityBulkShareResult_1.MinimalEntityBulkShareResult(x)))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccApplicationsettingsApi = IccApplicationsettingsApi;
//# sourceMappingURL=IccApplicationsettingsApi.js.map