"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clientWithoutCaseConverter = exports.isInOcm = exports.ocmClient = exports.client = exports.setAuthInterceptor = void 0;
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const axios_case_converter_1 = tslib_1.__importDefault(require("axios-case-converter"));
const camel_case_1 = require("camel-case");
const withAssistedInstallerBasePath = (client) => {
    // Conforms with basePath in swagger.json
    const basePath = '/api/assisted-install';
    client.interceptors.request.use((cfg) => {
        if (cfg.url) {
            try {
                const url = new URL(cfg.url);
                cfg.url = `${url.origin}${basePath}${url.pathname}${url.search}`;
            }
            catch (_a) {
                // This usually happens when the request is issued to a localhost endpoint.
                cfg.url = `${basePath}${cfg.url}`;
            }
        }
        return cfg;
    });
    return client;
};
let isInOcm = false;
exports.isInOcm = isInOcm;
let ocmClient;
let client = (0, axios_case_converter_1.default)(withAssistedInstallerBasePath(axios_1.default.create()), 
// Prevents the axios-case-converter from changing object keys from '4.7-fc2' to '4_7Fc2'
{
    caseFunctions: {
        camel: (input) => (0, camel_case_1.camelCase)(input, {
            stripRegexp: /[^A-Z0-9.-]+/gi,
        }),
    },
});
exports.client = client;
let clientWithoutCaseConverter = withAssistedInstallerBasePath(axios_1.default.create());
exports.clientWithoutCaseConverter = clientWithoutCaseConverter;
const setAuthInterceptor = (authInterceptor) => {
    exports.isInOcm = isInOcm = true;
    exports.ocmClient = ocmClient = authInterceptor(axios_1.default.create());
    // Instances of Axios with URL intercepted using Assisted-installer's base-path
    exports.client = client = authInterceptor(client);
    exports.clientWithoutCaseConverter = clientWithoutCaseConverter = authInterceptor(clientWithoutCaseConverter);
};
exports.setAuthInterceptor = setAuthInterceptor;
//# sourceMappingURL=axiosClient.js.map