"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.IccDataownerApi = 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 DataOwnerWithType_1 = require("../model/DataOwnerWithType");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const CryptoActorStub_1 = require("../model/CryptoActorStub");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccDataownerApi {
    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;
    }
    handleError(e) {
        throw e;
    }
    /**
     * General information about the current data owner. Note that this does not decrpyt patient data owners.
     * @summary Get the data owner corresponding to the current user
     */
    getCurrentDataOwner() {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/dataowner/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) => DataOwnerWithType_1.DataOwnerWithType.fromJson(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Full data owner information
     * @summary Get a data owner by his ID
     * @param dataOwnerId
     */
    getDataOwner(dataOwnerId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/dataowner/${encodeURIComponent(String(dataOwnerId))}` + '?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) => DataOwnerWithType_1.DataOwnerWithType.fromJson(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * General information about the keys of a data owner
     * @summary Get a data owner by his ID
     * @param dataOwnerId
     */
    getCryptoActorStub(dataOwnerId) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = null;
            const _url = this.host + `/dataowner/stub/${encodeURIComponent(String(dataOwnerId))}` + '?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 CryptoActorStub_1.CryptoActorStubWithType(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
    /**
     * Updates the keys of a data owner
     */
    modifyCryptoActorStub(stub) {
        return __awaiter(this, void 0, void 0, function* () {
            let _body = stub;
            const _url = this.host + `/dataowner/stub` + '?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 CryptoActorStub_1.CryptoActorStubWithType(doc.body))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccDataownerApi = IccDataownerApi;
//# sourceMappingURL=IccDataownerApi.js.map