"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.IccClassificationApi = 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 Classification_1 = require("../model/Classification");
const DocIdentifier_1 = require("../model/DocIdentifier");
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");
const ListOfIds_1 = require("../model/ListOfIds");
class IccClassificationApi {
    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;
    }
    /**
     * Returns an instance of created classification Template.
     * @summary Create a classification with the current user
     * @param body
     */
    createClassification(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/classification` + '?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 Classification_1.Classification(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a batch of classifications.
     *
     * @param classificationIds a ListOfIds containing the ids of the classification to delete.
     * @return a Promise that will resolve in an array of DocIdentifiers of the successfully deleted classifications.
     */
    deleteClassifications(classificationIds) {
        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 + `/classification/delete/batch` + '?ts=' + new Date().getTime(), headers, classificationIds, 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 classification by id.
     *
     * @param classificationId the id of the classification to delete.
     * @return a Promise that will resolve in the DocIdentifier of the deleted classification.
     */
    deleteClassification(classificationId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/classification/${encodeURIComponent(classificationId)}` + '?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));
        });
    }
    /**
     * Keys have to be delimited by comma
     * @deprecated use {@link findClassificationIdsByDataOwnerPatientCreated} instead.
     * @summary List classification Templates found By Healthcare Party and secret foreign keys.
     * @param hcPartyId
     * @param secretFKeys
     */
    findClassificationsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/classification/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '') +
                (secretFKeys ? '&secretFKeys=' + encodeURIComponent(String(secretFKeys)) : '');
            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 Classification_1.Classification(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary List Classification ids by data owner and a set of secret foreign key. The ids will be sorted by Classification created, in ascending or descending
     * order according to the specified parameter value.
     *
     * @param dataOwnerId the data owner id.
     * @param secretFKeys an array of secret foreign keys.
     * @param startDate a timestamp in epoch milliseconds. If undefined, all the classification ids since the beginning of time will be returned.
     * @param endDate a timestamp in epoch milliseconds. If undefined, all the classification ids until the end of time will be returned.
     * @param descending whether to return the ids ordered in ascending or descending order by Classification created
     * @return a promise that will resolve in an Array of Classification ids.
     */
    findClassificationIdsByDataOwnerPatientCreated(dataOwnerId, secretFKeys, startDate, endDate, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/classification/byDataOwnerPatientCreated?ts=${new Date().getTime()}` +
                '&dataOwnerId=' +
                encodeURIComponent(dataOwnerId) +
                (!!startDate ? `&startDate=${encodeURIComponent(startDate)}` : '') +
                (!!endDate ? `&endDate=${encodeURIComponent(endDate)}` : '') +
                (!!descending ? `&descending=${descending}` : '');
            const headers = (yield this.headers).filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
            const body = new ListOfIds_1.ListOfIds({ ids: secretFKeys });
            return XHR_1.XHR.sendCommand('POST', _url, headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => JSON.parse(JSON.stringify(it))))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get a classification Template
     * @param classificationId
     */
    getClassification(classificationId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/classification/${encodeURIComponent(String(classificationId))}` + '?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 Classification_1.Classification(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    getClassifications(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/classification/byIds` + '?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) => doc.body.map((it) => new Classification_1.Classification(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Get a list of classifications by their ids.
     * @param ids
     */
    getClassificationByHcPartyId(ids) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/classification/byIds` + '?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, ids, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Classification_1.Classification(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns the modified classification Template.
     * @summary Modify a classification Template
     * @param body
     */
    modifyClassification(body) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            _body = body;
            const _url = this.host + `/classification` + '?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 Classification_1.Classification(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareClassifications(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/classification/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, Classification_1.Classification)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareClassificationsMinimal(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/classification/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.IccClassificationApi = IccClassificationApi;
//# sourceMappingURL=IccClassificationApi.js.map