"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.IccMaintenanceTaskApi = 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 MaintenanceTask_1 = require("../model/MaintenanceTask");
const PaginatedListMaintenanceTask_1 = require("../model/PaginatedListMaintenanceTask");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const EntityBulkShareResult_1 = require("../model/requests/EntityBulkShareResult");
class IccMaintenanceTaskApi {
    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 Creates a maintenanceTask
     * @param body
     */
    createMaintenanceTask(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/maintenancetask` + '?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 MaintenanceTask_1.MaintenanceTask(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a batch of maintenanceTasks.
     *
     * @param maintenanceTaskIds a ListOfIds containing the ids of the maintenanceTasks to delete.
     * @return a Promise that will resolve in an array of DocIdentifiers of the successfully deleted maintenanceTasks.
     */
    deleteMaintenanceTasks(maintenanceTaskIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const headers = (yield this.headers).filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            return XHR_1.XHR.sendCommand('POST', this.host + `/maintenancetask/delete/batch` + '?ts=' + new Date().getTime(), headers, maintenanceTaskIds, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new DocIdentifier_1.DocIdentifier(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a single maintenanceTask by id.
     *
     * @param maintenanceTaskId the id of the maintenanceTask to delete.
     * @return a Promise that will resolve in the DocIdentifier of the deleted maintenanceTask.
     */
    deleteMaintenanceTask(maintenanceTaskId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/maintenancetask/${encodeURIComponent(maintenanceTaskId)}` + '?ts=' + new Date().getTime(), yield this.headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    filterMaintenanceTasksBy(startDocumentId_1, limit_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (startDocumentId, limit, body, collectTiming = false) {
            let _body = null;
            _body = body;
            const _url = this.host +
                `/maintenancetask/filter` +
                '?ts=' +
                new Date().getTime() +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            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(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(new PaginatedListMaintenanceTask_1.PaginatedListMaintenanceTask(doc.body), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets a maintenanceTask
     * @param maintenanceTaskId
     */
    getMaintenanceTask(maintenanceTaskId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/maintenancetask/${encodeURIComponent(String(maintenanceTaskId))}` + '?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) => new MaintenanceTask_1.MaintenanceTask(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Updates a maintenanceTask
     * @param body
     */
    modifyMaintenanceTask(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/maintenancetask` + '?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 MaintenanceTask_1.MaintenanceTask(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareMaintenanceTask(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/maintenancetask/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, MaintenanceTask_1.MaintenanceTask)))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccMaintenanceTaskApi = IccMaintenanceTaskApi;
//# sourceMappingURL=IccMaintenanceTaskApi.js.map