"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccReplicationApi = 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 ReplicatorDocument_1 = require("../model/ReplicatorDocument");
const ReplicatorResponse_1 = require("../model/ReplicatorResponse");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccReplicationApi {
    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;
    }
    /**
     * Create a document to start a continuous replication
     * @summary Create continuous replication document
     * @param body
     */
    createContinuousReplicationDoc(body) {
        const _url = this.host + `/replication/continuous` + '?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 ReplicatorResponse_1.ReplicatorResponse(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Create a document to start a one time replication
     * @summary Create one time replication document
     * @param body
     */
    createOneTimeReplicationDoc(body) {
        let _body = null;
        _body = body;
        const _url = this.host + `/replication/onetime` + '?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 ReplicatorResponse_1.ReplicatorResponse(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * DocId is the id provided by a replicator document from replication/docs
     * @summary Delete replication document to stop it
     * @param docId
     */
    deleteReplicationDoc(docId) {
        let _body = null;
        const _url = this.host + `/replication/stop/${encodeURIComponent(String(docId))}` + '?ts=' + new Date().getTime();
        let headers = this.headers;
        return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
            .then((doc) => new ReplicatorResponse_1.ReplicatorResponse(doc.body))
            .catch((err) => this.handleError(err));
    }
    /**
     * Get all replication infos and states
     * @summary Get replication documents
     */
    getReplicationDocs() {
        let _body = null;
        const _url = this.host + `/replication/docs` + '?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 ReplicatorDocument_1.ReplicatorDocument(it)))
            .catch((err) => this.handleError(err));
    }
}
exports.IccReplicationApi = IccReplicationApi;
//# sourceMappingURL=IccReplicationApi.js.map