"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.IccAccesslogApi = 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 AccessLog_1 = require("../model/AccessLog");
const DocIdentifier_1 = require("../model/DocIdentifier");
const PaginatedListAccessLog_1 = require("../model/PaginatedListAccessLog");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const EntityBulkShareResult_1 = require("../model/requests/EntityBulkShareResult");
const ListOfIds_1 = require("../model/ListOfIds");
class IccAccesslogApi {
    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 an access log
     * @param body
     */
    createAccessLog(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/accesslog` + '?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 AccessLog_1.AccessLog(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a batch of access logs.
     *
     * @param accessLogIds a ListOfIds containing the ids of the access logs to delete.
     * @return a Promise that will resolve in an array of DocIdentifiers of the successfully deleted access logs.
     */
    deleteAccessLogs(accessLogIds) {
        return __awaiter(this, void 0, void 0, function* () {
            const headers = yield this.headers;
            return XHR_1.XHR.sendCommand('POST', this.host + `/accesslog/delete/batch` + '?ts=' + new Date().getTime(), headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json')), accessLogIds, 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 access log by id.
     *
     * @param accessLogId the id of the access log.
     */
    deleteAccessLog(accessLogId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/accesslog/${encodeURIComponent(accessLogId)}` + '?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));
        });
    }
    /**
     * @deprecated use {@link findAccessLogIdsByDataOwnerPatientDate} instead.
     * @summary List access logs found by Healthcare Party and secret foreign keyelementIds.
     * @param body
     * @param hcPartyId
     */
    findAccessLogsByHCPartyPatientForeignKeysUsingPost(hcPartyId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/accesslog/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 AccessLog_1.AccessLog(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary List AccessLog ids by data owner and a set of secret foreign key. The ids will be sorted by AccessLog date, 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 access log ids since the beginning of time will be returned.
     * @param endDate a timestamp in epoch milliseconds. If undefined, all the access log ids until the end of time will be returned.
     * @param descending whether to return the ids ordered in ascending or descending order by AccessLog date
     * @return a promise that will resolve in an Array of AccessLog ids.
     */
    findAccessLogIdsByDataOwnerPatientDate(dataOwnerId, secretFKeys, startDate, endDate, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/accesslog/byDataOwnerPatientDate?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));
        });
    }
    /**
     * @deprecated use {@link findAccessLogIdsByDataOwnerPatientDate} instead
     * @summary List access logs found by Healthcare Party and secret foreign keyelementIds.
     * @param hcPartyId
     * @param secretFKeys
     */
    findAccessLogsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/accesslog/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 AccessLog_1.AccessLog(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get paginated list of Access Logs
     * @param userId A User ID
     * @param accessType The type of access (COMPUTER or USER)
     * @param startDate The start search epoch
     * @param startKey The start key for pagination
     * @param startDocumentId A patient document ID
     * @param limit Number of rows
     * @param descending Descending order
     */
    findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/accesslog/byUser` +
                '?ts=' +
                new Date().getTime() +
                (userId ? '&userId=' + encodeURIComponent(String(userId)) : '') +
                (accessType ? '&accessType=' + encodeURIComponent(String(accessType)) : '') +
                (startDate ? '&startDate=' + encodeURIComponent(String(startDate)) : '') +
                (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '') +
                (descending ? '&descending=' + encodeURIComponent(String(descending)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListAccessLog_1.PaginatedListAccessLog(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Get an access log
     * @param accessLogId
     */
    getAccessLog(accessLogId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/accesslog/${encodeURIComponent(String(accessLogId))}` + '?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 AccessLog_1.AccessLog(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Get a batch of Access Logs by their ids.
     * @param ids an array of ids.
     */
    getAccessLogs(ids) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/accesslog/byIds` + '?ts=' + new Date().getTime();
            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', _url, headers, ids, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new AccessLog_1.AccessLog(it)))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get paginated list of Access Logs
     * @param fromEpoch
     * @param toEpoch
     * @param startKey
     * @param startDocumentId
     * @param limit
     * @param descending
     */
    listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/accesslog` +
                '?ts=' +
                new Date().getTime() +
                (fromEpoch ? '&fromEpoch=' + encodeURIComponent(String(fromEpoch)) : '') +
                (toEpoch ? '&toEpoch=' + encodeURIComponent(String(toEpoch)) : '') +
                (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '') +
                (descending ? '&descending=' + encodeURIComponent(String(descending)) : '');
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, yield headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListAccessLog_1.PaginatedListAccessLog(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Get paginated list of Access Logs for a group
     * @param groupId
     * @param fromEpoch
     * @param toEpoch
     * @param startKey
     * @param startDocumentId
     * @param limit
     */
    listAccessLogsInGroup(groupId, fromEpoch, toEpoch, startKey, startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/accesslog/inGroup/${encodeURIComponent(String(groupId))}` +
                '?ts=' +
                new Date().getTime() +
                (fromEpoch ? '&fromEpoch=' + encodeURIComponent(String(fromEpoch)) : '') +
                (toEpoch ? '&toEpoch=' + encodeURIComponent(String(toEpoch)) : '') +
                (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            let headers = yield this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListAccessLog_1.PaginatedListAccessLog(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     *
     * @summary Modifies an access log
     * @param body
     */
    modifyAccessLog(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/accesslog` + '?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 AccessLog_1.AccessLog(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @internal this method is for internal use only and may be changed without notice
     */
    bulkShareAccessLogs(request) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + '/accesslog/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, AccessLog_1.AccessLog)))
                .catch((err) => this.handleError(err));
        });
    }
    matchAccessLogsBy(body_1) {
        return __awaiter(this, arguments, void 0, function* (body, collectTiming = false) {
            const _url = this.host + `/accessLog/match`;
            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(doc.body.map((it) => JSON.parse(JSON.stringify(it))), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    matchAccessLogsInGroupBy(groupId_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (groupId, body, collectTiming = false) {
            const _url = this.host + `/inGroup/${groupId}/match`;
            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(doc.body.map((it) => JSON.parse(JSON.stringify(it))), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccAccesslogApi = IccAccesslogApi;
//# sourceMappingURL=IccAccesslogApi.js.map