import { VITE_CONFIG_FILE_SEVER_URL } from "@/constants/constants";
import { httpNoAuth } from "@/plugins/axiosNoAuth";

export async function getGeeTestConfig(rootOrgId: number): Promise<boolean> {
  try {
    const res = await httpNoAuth.get(
      VITE_CONFIG_FILE_SEVER_URL +
        "/org_properties/geetestConfig.json" +
        "?" +
        Date.now() +
        Math.random(),
      { noErrorMessage: true, "axios-retry": { retries: 3 } }
    );
    // console.log(res.data);
    const gConf: Record<string, boolean> = res.data;
    return gConf["" + rootOrgId] ?? gConf["-1"];
  } catch (e) {
    logger({
      cnl: ["console", "local", "server"],
      pgu: "AUTO",
      ejn: JSON.stringify(e),
      stk: e instanceof Error ? e.stack : "not Error object." + e,
      dtl: "获取远程配置文件出错，请重新打开程序！",
      act: "fetch geetestConfig.json",
    });
    $message.error("获取远程配置文件出错，请重新打开程序！", {
      duration: 24 * 60 * 60 * 1000,
    });
    throw e;
  }
}
