"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.IccAnonymousAccessApi = 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 AppointmentTypeAndPlace_1 = require("../model/AppointmentTypeAndPlace");
const UserAndHealthcareParty_1 = require("../model/UserAndHealthcareParty");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
const PaginatedListMedicalLocation_1 = require("../model/PaginatedListMedicalLocation");
class IccAnonymousAccessApi {
    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;
    }
    /**
     * The start of the slot is returned in YYYYDDMMHHmmss format and only slots belonging to public time tables are returned.
     * @summary Get Availabilities for HCP and appointmentType
     * @param groupId
     * @param userId
     * @param calendarItemTypeId
     * @param isNewPatient
     * @param startDate
     * @param endDate
     * @param hcpId
     * @param placeId
     * @param limit
     */
    getAvailabilitiesByPeriodAndCalendarItemTypeId(groupId, userId, calendarItemTypeId, isNewPatient, startDate, endDate, hcpId, placeId, limit) {
        let _body = null;
        const _url = this.host +
            `/aa/available/inGroup/${encodeURIComponent(String(groupId))}/forUser/${encodeURIComponent(String(userId))}/type/${encodeURIComponent(String(calendarItemTypeId))}` +
            '?ts=' +
            new Date().getTime() +
            (isNewPatient !== null && isNewPatient !== undefined ? '&isNewPatient=' + encodeURIComponent(String(isNewPatient)) : '') +
            (startDate ? '&startDate=' + encodeURIComponent(String(startDate)) : '') +
            (endDate ? '&endDate=' + encodeURIComponent(String(endDate)) : '') +
            (hcpId ? '&hcpId=' + encodeURIComponent(String(hcpId)) : '') +
            (placeId ? '&placeId=' + encodeURIComponent(String(placeId)) : '') +
            (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _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));
    }
    /**
     * Returns a list of Calendar Item types. In order to be returned, the Calendar Item Type must be linked to a time table enclosed in an Agenda for which an anonymous right has been set (a Right with read permission and null user)
     * @summary List Calendar Item types for a provided group id and user id
     * @param groupId Healthcare parties group id
     * @param userId Healthcare party user id
     * @param startDate
     * @param endDate
     */
    listAppointmentTypesForUser(groupId, userId, startDate, endDate) {
        let _body = null;
        const _url = this.host +
            `/aa/appointmentType/inGroup/${encodeURIComponent(String(groupId))}/forUser/${encodeURIComponent(String(userId))}` +
            '?ts=' +
            new Date().getTime() +
            (startDate ? '&startDate=' + encodeURIComponent(String(startDate)) : '') +
            (endDate ? '&endDate=' + encodeURIComponent(String(endDate)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new AppointmentTypeAndPlace_1.AppointmentTypeAndPlace(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of Users/healthcare parties contained in the group owning the providing id. In order to be returned, a healthcare party needs to be linked to a user an this user must have a property 'org.taktik.icure.public' set to a boolean true.
     * @summary List healthcare parties for a provided group id
     * @param groupId Healthcare parties group id
     */
    listHealthcarePartiesInGroup(groupId) {
        let _body = null;
        const _url = this.host + `/aa/hcparty/inGroup/${encodeURIComponent(String(groupId))}` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => doc.body.map((it) => new UserAndHealthcareParty_1.UserAndHealthcareParty(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Get paginated list of Access Logs
     * @param groupId MedicalLocations group id
     * @param startKey The start key for pagination
     * @param startDocumentId A patient document ID
     * @param limit Number of rows
     */
    getPublicMedicalLocationsByGroupId(groupId, startKey, startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/aa/medicallocation/byGroup/${groupId}` +
                '?ts=' +
                new Date().getTime() +
                (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, undefined, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListMedicalLocation_1.PaginatedListMedicalLocation(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccAnonymousAccessApi = IccAnonymousAccessApi;
//# sourceMappingURL=IccAnonymousAccessApi.js.map