"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.IccCalendarItemApi = 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 CalendarItem_1 = require("../model/CalendarItem");
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 EntityBulkShareResult_1 = require("../model/requests/EntityBulkShareResult");
const MinimalEntityBulkShareResult_1 = require("../model/requests/MinimalEntityBulkShareResult");
const PaginatedListCalendarItem_1 = require("../model/PaginatedListCalendarItem");
class IccCalendarItemApi {
    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 calendarItem
     * @param body
     */
    createCalendarItem(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/calendarItem` + '?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 CalendarItem_1.CalendarItem(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a calendarItem by id.
     *
     * @summary Deletes an calendarItem
     * @param calendarItemId the id of calendarItem to delete.
     * @return a Promise that will resolve in the DocIdentifier of the deleted calendarItem.
     */
    deleteCalendarItem(calendarItemId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/calendarItem/${encodeURIComponent(calendarItemId)}` + '?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));
        });
    }
    /**
     * @summary Deletes a batch of calendarItems by id.
     *
     * @summary Deletes calendarItems
     * @param body a ListOfIds containing the ids of the calendarItems to delete.
     * @return a Promise that will resolve in an array of DocIdentifiers of the successfully deleted calendarItems.
     */
    deleteCalendarItems(body) {
        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 + `/calendarItem/delete/batch` + '?ts=' + new Date().getTime(), headers, body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new DocIdentifier_1.DocIdentifier(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated use {@link findCalendarItemIdsByDataOwnerPatientStartTime} instead.
     * @summary Find CalendarItems by hcparty and patient
     * @param body
     * @param hcPartyId
     */
    findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/calendarItem/byHcPartySecretForeignKeys` +
                '?ts=' +
                new Date().getTime() +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            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 CalendarItem_1.CalendarItem(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated use {@link findCalendarItemIdsByDataOwnerPatientStartTime} instead.
     * @summary Find CalendarItems by hcparty and patient
     * @param hcPartyId
     * @param secretFKeys
     */
    findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/calendarItem/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 CalendarItem_1.CalendarItem(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated use {@link findCalendarItemsByRecurrenceIdWithPagination} instead.
     *
     * @summary Find CalendarItems by recurrenceId
     * @param recurrenceId
     */
    findCalendarItemsByRecurrenceId(recurrenceId) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/calendarItem/byRecurrenceId?ts=${new Date().getTime()}&recurrenceId=${encodeURIComponent(recurrenceId)}&limit=1000000`;
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => { var _a; return (_a = new PaginatedListCalendarItem_1.PaginatedListCalendarItem(doc.body).rows) !== null && _a !== void 0 ? _a : []; })
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Find CalendarItems by recurrenceId
     * @param recurrenceId the recurrence id.
     * @param startKey the startKey provided by the previous page or undefined for the first page.
     * @param startDocumentId the startDocumentId provided by the previous page or undefined for the first page.
     * @param limit the number of elements that the page should contain.
     * @return a promise that will resolve in a PaginatedListAccessLog.
     */
    findCalendarItemsByRecurrenceIdWithPagination(recurrenceId, startKey, startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/calendarItem/byRecurrenceId?ts=${new Date().getTime()}&recurrenceId=${encodeURIComponent(recurrenceId)}` +
                (!!startKey ? `&startKey=${encodeURIComponent(startKey)}` : '') +
                (!!startDocumentId ? `&startDocumentId=${encodeURIComponent(startDocumentId)}` : '') +
                (!!limit ? `&limit=${limit}` : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListCalendarItem_1.PaginatedListCalendarItem(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Gets a calendarItem
     * @param calendarItemId
     */
    getCalendarItem(calendarItemId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/calendarItem/${encodeURIComponent(String(calendarItemId))}` + '?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 CalendarItem_1.CalendarItem(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @deprecated use {@link getCalendarItemsWithPagination} instead
     *
     * @summary Gets all calendarItems
     */
    getCalendarItems() {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/calendarItem?ts=${new Date().getTime()}$limit=1000000`;
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => { var _a; return (_a = new PaginatedListCalendarItem_1.PaginatedListCalendarItem(doc.body).rows) !== null && _a !== void 0 ? _a : []; })
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary gets all Calendar Items with pagination.
     *
     * @param startDocumentId the startDocumentId provided by the previous page or null if it's the first page.
     * @param limit the size of the page
     * @return a promise that will resolve in a PaginatedListCalendarItem.
     */
    getCalendarItemsWithPagination(startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/calendarItem` +
                '?ts=' +
                new Date().getTime() +
                (!!startDocumentId ? `&startDocumentId=${encodeURIComponent(startDocumentId)}` : '') +
                (!!limit ? `&limit=${limit}` : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListCalendarItem_1.PaginatedListCalendarItem(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get CalendarItems by Period and HcPartyId
     * @param startDate
     * @param endDate
     * @param hcPartyId
     */
    getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/calendarItem/byPeriodAndHcPartyId` +
                '?ts=' +
                new Date().getTime() +
                (startDate ? '&startDate=' + encodeURIComponent(String(startDate)) : '') +
                (endDate ? '&endDate=' + encodeURIComponent(String(endDate)) : '') +
                (hcPartyId ? '&hcPartyId=' + encodeURIComponent(String(hcPartyId)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new CalendarItem_1.CalendarItem(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get calendarItems by id
     * @param body
     */
    getCalendarItemsWithIds(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/calendarItem/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 CalendarItem_1.CalendarItem(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get CalendarItems by Period and AgendaId
     * @param startDate
     * @param endDate
     * @param agendaId
     */
    getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/calendarItem/byPeriodAndAgendaId` +
                '?ts=' +
                new Date().getTime() +
                (startDate ? '&startDate=' + encodeURIComponent(String(startDate)) : '') +
                (endDate ? '&endDate=' + encodeURIComponent(String(endDate)) : '') +
                (agendaId ? '&agendaId=' + encodeURIComponent(String(agendaId)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new CalendarItem_1.CalendarItem(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Modifies an calendarItem
     * @param body
     */
    modifyCalendarItem(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/calendarItem` + '?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 CalendarItem_1.CalendarItem(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareCalendarItems(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/calendarItem/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, CalendarItem_1.CalendarItem)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareCalendarItemsMinimal(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/calendarItem/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));
        });
    }
    /**
     * @summary List CalendarItem ids by data owner and a set of secret foreign key. The ids will be sorted by CalendarItem startTime, 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 calendar item ids since the beginning of time will be returned.
     * @param endDate a timestamp in epoch milliseconds. If undefined, all the calendar item ids until the end of time will be returned.
     * @param descending whether to return the ids ordered in ascending or descending order by CalendarItem startTime
     * @return a promise that will resolve in an Array of CalendarItem ids.
     */
    findCalendarItemIdsByDataOwnerPatientStartTime(dataOwnerId, secretFKeys, startDate, endDate, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/calendarItem/byDataOwnerPatientStartTime?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));
        });
    }
}
exports.IccCalendarItemApi = IccCalendarItemApi;
//# sourceMappingURL=IccCalendarItemApi.js.map