import axios from "axios";
import { getAppConfigValue } from "../../utils/app-config/config.js";
import { getAuthorizationHeader } from "../../utils/auth/helper.js";
import setupRetry from "./retry.js";
import { requestInterceptor } from "./request-interceptor.js";
import { handleSuccess, handleFailure } from "./response-interceptor.js";
import { getLogRocket } from "../../utils/logrocket.js";
const REQUEST_TIMEOUT = 2 * 60 * 1e3;
const getHTTPClient = ({
  baseURL = getAppConfigValue("serviceEndpoints.api", ""),
  headers = {},
  sendLogRocketSessionHeader = false
} = {}) => {
  const logRocketSessionUrl = getLogRocket()?.sessionURL || "";
  const client = axios.create({
    baseURL,
    headers: sendLogRocketSessionHeader && logRocketSessionUrl ? { ...headers, "X-LogRocket-URL": logRocketSessionUrl } : headers
  });
  if (client?.defaults?.timeout) client.defaults.timeout = REQUEST_TIMEOUT;
  setupRetry(client);
  const { request, response } = client?.interceptors || {};
  if (request) request.use(requestInterceptor);
  if (response) response.use(handleSuccess, handleFailure);
  return client;
};
const getAuthHTTPClient = ({
  baseURL,
  headers = {},
  sendLogRocketSessionHeader = false,
  ...rest
} = {}) => getHTTPClient({
  baseURL,
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  headers: { ...headers, Authorization: getAuthorizationHeader() },
  sendLogRocketSessionHeader,
  ...rest
});
export {
  getAuthHTTPClient,
  getAuthorizationHeader,
  getHTTPClient
};
