"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.IccHcpartyApi = 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 DataOwnerRegistrationSuccess_1 = require("../model/DataOwnerRegistrationSuccess");
const DocIdentifier_1 = require("../model/DocIdentifier");
const HealthcareParty_1 = require("../model/HealthcareParty");
const PaginatedListHealthcareParty_1 = require("../model/PaginatedListHealthcareParty");
const PublicKey_1 = require("../model/PublicKey");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccHcpartyApi {
    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;
    }
    /**
     * One of Name or Last name+First name, Nihii, and Public key are required.
     * @summary Create a healthcare party
     * @param body
     */
    createHealthcareParty(body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/hcparty` + '?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 HealthcareParty_1.HealthcareParty(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * One of Name or Last name+First name, Nihii, and Public key are required.
     * @summary Create a healthcare party
     * @param body
     * @param groupId
     */
    createHealthcarePartyInGroup(groupId, body) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/hcparty/inGroup/${encodeURIComponent(String(groupId))}` + '?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 HealthcareParty_1.HealthcareParty(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * @summary Deletes a healthcare parties in batch.
     * @param healthcarePartyIds a ListOfIds containing the ids of the healthcare parties to delete.
     * @return a Promise that will resolve in an Array of DocIdentifiers of the successfully deleted healthcare parties.
     */
    deleteHealthcareParties(healthcarePartyIds) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('POST', this.host + `/hcparty/delete/batch` + '?ts=' + new Date().getTime(), this.headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json')), healthcarePartyIds, 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 healthcare party by id.
     *
     * @param healthcarePartyId the id of the healthcare party to delete.
     * @return a Promise that will resolve in the DocIdentifier of the healthcare party.
     */
    deleteHealthcareParty(healthcarePartyId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/hcparty/${encodeURIComponent(healthcarePartyId)}` + '?ts=' + new Date().getTime(), 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 healthcare parties in batch in a specific group
     * @param groupId the id of the group where to delete the healthcare parties.
     * @param healthcarePartyIds a ListOfIds containing the ids of the healthcare parties to delete.
     * @return a Promise that will resolve in an Array of DocIdentifiers of the successfully deleted healthcare parties.
     */
    deleteHealthcarePartiesInGroup(groupId, healthcarePartyIds) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('POST', this.host + `/hcparty/delete/batch/inGroup/${encodeURIComponent(groupId)}` + '?ts=' + new Date().getTime(), this.headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json')), healthcarePartyIds, 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 healthcare party by id in a specific group.
     *
     * @param groupId the id of the group where to delete the healthcare party.
     * @param healthcarePartyId the id of the healthcare party to delete.
     * @return a Promise that will resolve in the DocIdentifier of the healthcare party.
     */
    deleteHealthcarePartyInGroup(groupId, healthcarePartyId) {
        return __awaiter(this, void 0, void 0, function* () {
            return XHR_1.XHR.sendCommand('DELETE', this.host + `/hcparty/${encodeURIComponent(healthcarePartyId)}/inGroup/${encodeURIComponent(groupId)}` + '?ts=' + new Date().getTime(), this.headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new DocIdentifier_1.DocIdentifier(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    filterHealthPartiesBy(startDocumentId_1, limit_1, body_1) {
        return __awaiter(this, arguments, void 0, function* (startDocumentId, limit, body, collectTiming = false) {
            const _url = this.host +
                `/hcparty/filter` +
                '?ts=' +
                new Date().getTime() +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '');
            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(), undefined, false, collectTiming ? ['x-filter-timing-*'] : [])
                .then((doc) => Object.assign(new PaginatedListHealthcareParty_1.PaginatedListHealthcareParty(doc.body), collectTiming ? { responseHeaders: doc.responseHeaders } : {}))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of healthcare parties.
     * @summary Find healthcare parties by name with(out) pagination
     * @param name The Last name search value
     * @param startKey A healthcare party Last name
     * @param startDocumentId A healthcare party document ID
     * @param limit Number of rows
     * @param desc Descending
     */
    findByName(name, startKey, startDocumentId, limit, desc) {
        let _body = null;
        const _url = this.host +
            `/hcparty/byName` +
            '?ts=' +
            new Date().getTime() +
            (name ? '&name=' + encodeURIComponent(String(name)) : '') +
            (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
            (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
            (limit ? '&limit=' + encodeURIComponent(String(limit)) : '') +
            (desc ? '&desc=' + encodeURIComponent(String(desc)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new PaginatedListHealthcareParty_1.PaginatedListHealthcareParty(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of healthcare parties.
     * @summary Find healthcare parties by name with(out) pagination
     * @param type The type of the HCP (persphysician)
     * @param spec The speciality of the HCP
     * @param firstCode The first postCode for the HCP
     * @param lastCode The last postCode for the HCP
     * @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 Number of rows
     */
    findBySpecialityAndPostCode(type, spec, firstCode, lastCode, startKey, startDocumentId, limit) {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host +
                `/hcparty/bySpecialityAndPostCode/${encodeURIComponent(type)}/${encodeURIComponent(spec)}/${encodeURIComponent(firstCode)}/to/${encodeURIComponent(lastCode)}` +
                '?ts=' +
                new Date().getTime() +
                +(!!startKey ? `&startKey=${encodeURIComponent(startKey)}` : '') +
                (!!startDocumentId ? `&startDocumentId=${encodeURIComponent(startDocumentId)}` : '') +
                (!!limit ? `&limit=${limit}` : '');
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListHealthcareParty_1.PaginatedListHealthcareParty(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Returns a list of healthcare parties.
     * @summary Find healthcare parties by nihii or ssin with(out) pagination
     * @param searchValue
     * @param startKey A healthcare party Last name
     * @param startDocumentId A healthcare party document ID
     * @param limit Number of rows
     * @param desc Descending
     */
    findBySsinOrNihii(searchValue, startKey, startDocumentId, limit, desc) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host +
                `/hcparty/byNihiiOrSsin/${encodeURIComponent(String(searchValue))}` +
                '?ts=' +
                new Date().getTime() +
                (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
                (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
                (limit ? '&limit=' + encodeURIComponent(String(limit)) : '') +
                (desc ? '&desc=' + encodeURIComponent(String(desc)) : '');
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => new PaginatedListHealthcareParty_1.PaginatedListHealthcareParty(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * (key, value) of the map is as follows: (ID of the owner of the encrypted AES key, encrypted AES keys)
     * @summary Get the HcParty encrypted AES keys indexed by owner.
     * @param healthcarePartyId
     */
    getAesExchangeKeysForDelegate(healthcarePartyId) {
        let _body = null;
        const _url = this.host + `/hcparty/${encodeURIComponent(String(healthcarePartyId))}/aesExchangeKeys` + '?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) => JSON.parse(JSON.stringify(doc.body)))
            .catch((err) => this.handleError(err));
    }
    /**
     * General information about the current healthcare Party
     * @summary Get the current healthcare party if logged in.
     */
    getCurrentHealthcareParty() {
        let _body = null;
        const _url = this.host + `/hcparty/current` + '?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) => new HealthcareParty_1.HealthcareParty(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * General information about the healthcare Party
     * @summary Get healthcareParties by their IDs
     */
    getHealthcareParties(body) {
        let _body = body;
        const _url = this.host + '/hcparty/byIds?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 HealthcareParty_1.HealthcareParty(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Return a list of children hcp.
     * @summary Find children of an healthcare parties
     * @param parentId
     */
    getHealthcarePartiesByParentId(parentId) {
        let _body = null;
        const _url = this.host + `/hcparty/${encodeURIComponent(String(parentId))}/children` + '?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 HealthcareParty_1.HealthcareParty(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * General information about the healthcare Party
     * @summary Get healthcareParties by their IDs
     * @param body
     * @param groupId
     */
    getHealthcarePartiesInGroup(groupId, body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/hcparty/inGroup/${encodeURIComponent(String(groupId))}/byIds` + '?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 HealthcareParty_1.HealthcareParty(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * General information about the healthcare Party
     * @summary Get a healthcareParty by his ID
     * @param healthcarePartyId
     */
    getHealthcareParty(healthcarePartyId) {
        let _body = null;
        const _url = this.host + `/hcparty/${encodeURIComponent(String(healthcarePartyId))}` + '?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) => new HealthcareParty_1.HealthcareParty(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns the public key of a healthcare party in Hex
     * @summary Get public key of a healthcare party
     * @param healthcarePartyId
     */
    getPublicKey(healthcarePartyId) {
        let _body = null;
        const _url = this.host + `/hcparty/${encodeURIComponent(String(healthcarePartyId))}/publicKey` + '?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) => new PublicKey_1.PublicKey(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of healthcare parties.
     * @summary Find healthcare parties by name with(out) pagination
     * @param name The Last name search value
     */
    listByName(name) {
        let _body = null;
        const _url = this.host + `/hcparty/byNameStrict/${encodeURIComponent(String(name))}` + '?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 HealthcareParty_1.HealthcareParty(it)))
            .catch((err) => this.handleError(err));
    }
    /**
     * Returns a list of healthcare parties.
     * @summary List healthcare parties with(out) pagination
     * @param startKey A healthcare party Last name
     * @param startDocumentId A healthcare party document ID
     * @param limit Number of rows
     * @param desc Descending
     */
    listHealthcareParties(startKey, startDocumentId, limit, desc) {
        let _body = null;
        const _url = this.host +
            `/hcparty` +
            '?ts=' +
            new Date().getTime() +
            (startKey ? '&startKey=' + encodeURIComponent(String(startKey)) : '') +
            (startDocumentId ? '&startDocumentId=' + encodeURIComponent(String(startDocumentId)) : '') +
            (limit ? '&limit=' + encodeURIComponent(String(limit)) : '') +
            (desc ? '&desc=' + encodeURIComponent(String(desc)) : '');
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new PaginatedListHealthcareParty_1.PaginatedListHealthcareParty(doc.body))
            .catch((err) => this.handleError(err));
    }
    matchHealthcarePartiesBy(body, collectTiming = false) {
        let _body = null;
        _body = body;
        const _url = this.host + `/hcparty/match` + '?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(), 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));
    }
    /**
     * No particular return value. It's just a message.
     * @summary Modify a Healthcare Party.
     * @param body
     */
    modifyHealthcareParty(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/hcparty` + '?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 HealthcareParty_1.HealthcareParty(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * No particular return value. It's just a message.
     * @summary Modify a Healthcare Party.
     * @param body
     * @param groupId
     */
    modifyHealthcarePartyInGroup(groupId, body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/hcparty/inGroup/${encodeURIComponent(String(groupId))}` + '?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 HealthcareParty_1.HealthcareParty(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Register a new hcp into the system
     * @summary Register a hcp
     * @param body
     * @param groupId
     * @param parentHcPartyId
     * @param token
     * @param useShortToken
     */
    registerHealthcareParty(groupId, parentHcPartyId, token, useShortToken, body) {
        let _body = null;
        _body = body;
        const _url = this.host +
            `/hcparty/register/inGroup/${encodeURIComponent(String(groupId))}` +
            '?ts=' +
            new Date().getTime() +
            (parentHcPartyId ? '&parentHcPartyId=' + encodeURIComponent(String(parentHcPartyId)) : '') +
            (token ? '&token=' + encodeURIComponent(String(token)) : '') +
            (useShortToken ? '&useShortToken=' + encodeURIComponent(String(useShortToken)) : '');
        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 DataOwnerRegistrationSuccess_1.DataOwnerRegistrationSuccess(doc.body))
            .catch((err) => this.handleError(err));
    }
}
exports.IccHcpartyApi = IccHcpartyApi;
//# sourceMappingURL=IccHcpartyApi.js.map