import "@seamless/logger";
import { g as A } from "./get-environment-data.mjs";
import "@seamless/store";
import "./with-usage-tracking.mjs";
const O = /* @__PURE__ */ new Set([
  "DE",
  "SE",
  "AT",
  "BE",
  "CH",
  "CZ",
  "DK",
  "SK",
  "ES",
  "FR",
  "HU",
  "IT",
  "LU",
  "NL",
  "PL",
  "PT",
  "RO"
]), P = /* @__PURE__ */ new Set([
  "SG",
  "AU",
  "ID",
  "IN",
  "JP",
  "KR",
  "MY",
  "NZ",
  "TH",
  "TR",
  "VN",
  "EG",
  "ZA",
  "BR"
]), C = /* @__PURE__ */ new Set(["US", "CA", "MX"]), a = {
  EU: "EU",
  AP: "AP",
  NA: "NA"
};
function T(n, t) {
  for (const [e, i] of t.entries())
    if (i.has(n))
      return e;
}
const r = {
  LOCAL: "local",
  DEVELOP: "dev",
  TEST: "test",
  INT: "int",
  PPROD: "pprod",
  PROD: "prod"
}, u = {
  DEV: "https://dev.api.oneweb.mercedes-benz.com",
  INT: "https://int.api.oneweb.mercedes-benz.com",
  PROD: "https://api.oneweb.mercedes-benz.com"
};
function m(n) {
  return Object.values(r).includes(n);
}
function w(n) {
  const t = n.toLowerCase();
  if (!m(t))
    throw new Error(`Invalid stage: "${n}". Expected one of: ${Object.values(r).join(", ")}`);
  return t;
}
const N = /* @__PURE__ */ new Map([
  [a.EU, O],
  [a.AP, P],
  [a.NA, C]
]);
async function y(n, t = []) {
  const { pageEnvironmentVariables: e, environmentVariables: i } = await A("iam-shared"), { country: o, stage: c } = e, { apiUrl: g } = i;
  if (!l(o) || !l(c))
    throw new Error("Missing required AEM config: country and stage are required to resolve a service URL");
  const f = $(o), s = w(c), { stageUrls: S, regionCountryMap: R } = D(n), d = S[s];
  if (t.includes(s))
    return E(d, o, s);
  const p = T(f, R);
  if (p) {
    const U = i[`apiUrl${p}`];
    if (U)
      return E(`${U}/${n}`, o, s);
  }
  if (g)
    return E(`${g}/${n}`, o, s);
  throw new Error(`Unable to resolve service URL for country "${o}" and stage "${c}"`);
}
function E(n, t, e) {
  return { serviceUrl: n, country: t, stage: e };
}
function l(n) {
  return typeof n == "string" && n.length > 0;
}
function $(n) {
  return n.trim().toUpperCase();
}
function D(n) {
  const t = `${u.DEV}/${n}`, e = `${u.INT}/${n}`, i = `${u.PROD}/${n}`;
  return {
    stageUrls: {
      [r.LOCAL]: t,
      [r.DEVELOP]: t,
      [r.TEST]: e,
      [r.INT]: e,
      [r.PPROD]: e,
      [r.PROD]: i
    },
    regionCountryMap: N
  };
}
export {
  u as B,
  r as S,
  y as g,
  m as i,
  w as n
};
//# sourceMappingURL=get-service-region-config.mjs.map
