"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const axiosClient_1 = require("../../api/axiosClient");
const InfraEnvsAPI_1 = tslib_1.__importDefault(require("./InfraEnvsAPI"));
let _getRequestAbortController = new AbortController();
const HostsAPI = {
    abortLastGetRequest() {
        _getRequestAbortController.abort();
        /**
         * The AbortController.signal can only be aborted once per instance.
         * Therefore in order for other requests to be also abortable we need
         * to create a new instance when this event occurs
         */
        _getRequestAbortController = new AbortController();
    },
    makeBaseURI(infraEnvId, hostId) {
        return `${InfraEnvsAPI_1.default.makeBaseURI(infraEnvId)}/hosts/${hostId ? hostId : ''}`;
    },
    makeActionsBaseURI(infraEnvId, hostId) {
        return `${HostsAPI.makeBaseURI(infraEnvId, hostId)}/actions`;
    },
    list(infraEnvId) {
        return axiosClient_1.client.get(`${HostsAPI.makeBaseURI(infraEnvId)}`, {
            signal: _getRequestAbortController.signal,
        });
    },
    get(infraEnvId, hostId) {
        return axiosClient_1.client.get(`${HostsAPI.makeBaseURI(infraEnvId, hostId)}`, {
            signal: _getRequestAbortController.signal,
        });
    },
    update(infraEnvId, hostId, params) {
        return axiosClient_1.client.patch(`${HostsAPI.makeBaseURI(infraEnvId, hostId)}`, params);
    },
    deregister(infraEnvId, hostId) {
        return axiosClient_1.client.delete(`${HostsAPI.makeBaseURI(infraEnvId, hostId)}`);
    },
    reset(infraEnvId, hostId) {
        return axiosClient_1.client.post(`${HostsAPI.makeActionsBaseURI(infraEnvId, hostId)}/reset`);
    },
    installHost(infraEnvId, hostId) {
        return axiosClient_1.client.post(`${HostsAPI.makeActionsBaseURI(infraEnvId, hostId)}/install`);
    },
    bindHost(infraEnvId, hostId, clusterId) {
        return axiosClient_1.client.post(`${HostsAPI.makeActionsBaseURI(infraEnvId, hostId)}/bind`, { cluster_id: clusterId }, {
            headers: {
                accept: 'application/json',
                'Content-Type': 'application/json',
            },
        });
    },
};
exports.default = HostsAPI;
//# sourceMappingURL=HostsAPI.js.map