"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var http_client_exports = {};
__export(http_client_exports, {
  getAuthHTTPClient: () => getAuthHTTPClient,
  getAuthorizationHeader: () => import_helper.getAuthorizationHeader,
  getHTTPClient: () => getHTTPClient
});
module.exports = __toCommonJS(http_client_exports);
var import_axios = __toESM(require("axios"));
var import_config = require("../../utils/app-config/config.js");
var import_helper = require("../../utils/auth/helper.js");
var import_retry = __toESM(require("./retry.js"));
var import_request_interceptor = require("./request-interceptor.js");
var import_response_interceptor = require("./response-interceptor.js");
var import_logrocket = require("../../utils/logrocket.js");
const REQUEST_TIMEOUT = 2 * 60 * 1e3;
const getHTTPClient = ({
  baseURL = (0, import_config.getAppConfigValue)("serviceEndpoints.api", ""),
  headers = {},
  sendLogRocketSessionHeader = false
} = {}) => {
  const logRocketSessionUrl = (0, import_logrocket.getLogRocket)()?.sessionURL || "";
  const client = import_axios.default.create({
    baseURL,
    headers: sendLogRocketSessionHeader && logRocketSessionUrl ? { ...headers, "X-LogRocket-URL": logRocketSessionUrl } : headers
  });
  if (client?.defaults?.timeout) client.defaults.timeout = REQUEST_TIMEOUT;
  (0, import_retry.default)(client);
  const { request, response } = client?.interceptors || {};
  if (request) request.use(import_request_interceptor.requestInterceptor);
  if (response) response.use(import_response_interceptor.handleSuccess, import_response_interceptor.handleFailure);
  return client;
};
const getAuthHTTPClient = ({
  baseURL,
  headers = {},
  sendLogRocketSessionHeader = false,
  ...rest
} = {}) => getHTTPClient({
  baseURL,
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  headers: { ...headers, Authorization: (0, import_helper.getAuthorizationHeader)() },
  sendLogRocketSessionHeader,
  ...rest
});
