"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const axiosClient_1 = require("../../api/axiosClient");
let _getRequestAbortController = new AbortController();
const InfraEnvsAPI = {
    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) {
        return `/v2/infra-envs/${infraEnvId ? infraEnvId : ''}`;
    },
    /**
     * Retrieves the list of infra-envs.
     * @param clusterId If provided, returns only infra-envs which directly reference the given clusterId.
     */
    list(clusterId = '') {
        const query = clusterId && `?${new URLSearchParams({ ['cluster_id']: clusterId }).toString()}`;
        return axiosClient_1.client.get(`${InfraEnvsAPI.makeBaseURI()}${query}`, {
            signal: _getRequestAbortController.signal,
        });
    },
    get(infraEnvId) {
        return axiosClient_1.client.get(`${InfraEnvsAPI.makeBaseURI(infraEnvId)}`, {
            signal: _getRequestAbortController.signal,
        });
    },
    update(infraEnvId, params) {
        return axiosClient_1.client.patch(`${InfraEnvsAPI.makeBaseURI(infraEnvId)}`, params);
    },
    register(params) {
        return axiosClient_1.client.post(`${InfraEnvsAPI.makeBaseURI()}`, params);
    },
    deregister(infraEnvId) {
        return axiosClient_1.client.delete(`${InfraEnvsAPI.makeBaseURI(infraEnvId)}`);
    },
    getImageUrl(infraEnvId) {
        return axiosClient_1.client.get(`${InfraEnvsAPI.makeBaseURI(infraEnvId)}/downloads/image-url`);
    },
    getIpxeImageUrl(infraEnvId) {
        return axiosClient_1.client.get(`${InfraEnvsAPI.makeBaseURI(infraEnvId)}/downloads/files-presigned?file_name=ipxe-script`);
    },
    getHosts(infraEnvId) {
        return axiosClient_1.client.get(`${InfraEnvsAPI.makeBaseURI(infraEnvId)}/hosts`, {
            signal: _getRequestAbortController.signal,
        });
    },
};
exports.default = InfraEnvsAPI;
//# sourceMappingURL=InfraEnvsAPI.js.map