import { DecodeError as h } from "@accelbyte/sdk";
import { AppName as e } from "./accelbyte-widgets78.mjs";
import { ConfigError as s, ConfigErrorCode as T } from "./accelbyte-widgets119.mjs";
import { ErrorHelper as I } from "./accelbyte-widgets120.mjs";
import C from "./accelbyte-widgets459.mjs";
import c from "./accelbyte-widgets460.mjs";
import E from "./accelbyte-widgets115.mjs";
import a from "./accelbyte-widgets461.mjs";
import D from "./accelbyte-widgets462.mjs";
import g from "./accelbyte-widgets463.mjs";
import { OdinConfig as m } from "./accelbyte-widgets464.mjs";
import { DISCOVERY_TEMPLATE_NAME as O } from "./accelbyte-widgets465.mjs";
const p = class {
};
let u = p;
u.fetchDiscovery = async ({
  sdk: n,
  appName: t,
  widgetOptions: f,
  useConfigService: l
}) => {
  var i;
  if (f)
    return f;
  if (t !== e.WIDGET && !l)
    return C;
  try {
    return await m.TemplatesApi(n).getConfigs_ByTemplate(O);
  } catch (o) {
    throw I.isAxiosError(o) && ((i = o.response) == null ? void 0 : i.status) === 404 ? new s("Template discovery not found", t, T.NO_DISCOVERY_TEMPLATE_FOUND) : o instanceof h ? new s("Invalid configs structure", t, T.INVALID_CONFIGS) : o;
  }
};
u.fetchConfigs = async ({
  sdk: n,
  appName: t,
  discoveryData: f,
  widgetOptions: l,
  useConfigService: i
}) => {
  if (l)
    return l;
  if (t !== e.WIDGET && !i)
    return t === e.LAUNCHER ? c : t === e.TWITCHDROP ? a : t === e.SUPPORT ? D : t === e.LOGIN ? g : E;
  let o = "";
  const r = f || await p.fetchDiscovery({ sdk: n, appName: t, useConfigService: i });
  if (!(r != null && r.ppTemplateInfo) && !(r != null && r.launcherTemplateInfo) && !(r != null && r.twitchDropTemplateInfo) && !(r != null && r.loginTemplateInfo))
    throw new s("No templates have been published.", t, T.NO_TEMPLATES_FOUND);
  return t === e.PP || t === e.WIDGET ? o = r.ppTemplateInfo.data.published : t === e.LAUNCHER ? o = r.launcherTemplateInfo.data.published : t === e.TWITCHDROP ? o = r.twitchDropTemplateInfo.data.published : t === e.SUPPORT ? o = r.supportTemplateInfo.data.published : t === e.LOGIN && (o = r.loginTemplateInfo.data.published), await m.TemplatesApi(n).getConfigs_ByTemplate(o);
};
export {
  u as FetchConfigsUtils
};
