"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccBemikronoApi = 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 Appointment_1 = require("../model/Appointment");
const MikronoAppointmentTypeRest_1 = require("../model/MikronoAppointmentTypeRest");
const Unit_1 = require("../model/Unit");
const User_1 = require("../model/User");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccBemikronoApi {
    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 Get appointments for patient
     * @param calendarDate
     */
    appointmentsByDate(calendarDate) {
        let _body = null;
        const _url = this.host + `/be_mikrono/appointments/byDate/${encodeURIComponent(String(calendarDate))}` + '?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 Appointment_1.Appointment(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Get appointments for patient
     * @param patientId
     * @param from
     * @param to
     */
    appointmentsByPatient(patientId, from, to) {
        let _body = null;
        const _url = this.host +
            `/be_mikrono/appointments/byPatient/${encodeURIComponent(String(patientId))}` +
            '?ts=' +
            new Date().getTime() +
            (from ? '&from=' + encodeURIComponent(String(from)) : '') +
            (to ? '&to=' + encodeURIComponent(String(to)) : '');
        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 Appointment_1.Appointment(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @param body
     */
    createAppointmentTypes(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/be_mikrono/appointmentTypes` + '?ts=' + new Date().getTime();
        let headers = 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 MikronoAppointmentTypeRest_1.MikronoAppointmentTypeRest(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Create appointments for owner
     * @param body
     */
    createAppointments(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/be_mikrono/appointments` + '?ts=' + new Date().getTime();
        let headers = 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) => JSON.parse(JSON.stringify(it))))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Notify of an appointment change
     * @param appointmentId
     * @param action
     */
    notify(appointmentId, action) {
        let _body = null;
        const _url = this.host +
            `/be_mikrono/notify/${encodeURIComponent(String(appointmentId))}/${encodeURIComponent(String(action))}` +
            '?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) => true)
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Set credentials for provided user
     * @param body
     * @param userId
     */
    register(userId, body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/be_mikrono/user/${encodeURIComponent(String(userId))}/register` + '?ts=' + new Date().getTime();
        let headers = 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 User_1.User(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Send message using mikrono from logged user
     * @param body
     */
    sendMessage(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/be_mikrono/sendMessage` + '?ts=' + new Date().getTime();
        let headers = 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 Unit_1.Unit(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     *
     * @summary Set credentials for provided user
     * @param body
     * @param userId
     */
    setUserCredentials(userId, body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/be_mikrono/user/${encodeURIComponent(String(userId))}/credentials` + '?ts=' + new Date().getTime();
        let headers = 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 User_1.User(doc.body))
            .catch((err) => this.handleError(err));
    }
}
exports.IccBemikronoApi = IccBemikronoApi;
//# sourceMappingURL=IccBemikronoApi.js.map