import { getAdminMe } from "@/api/admin-auth";
import type { AdminAuthMeResponse } from "@/types/api/admin-auth";

let inflightMe: Promise<AdminAuthMeResponse> | null = null;

/** 合并并发的 `/auth/me` 请求，避免 rehydrate 与 ShellAuthGate 重复打接口 */
export function fetchAdminMeDeduped(): Promise<AdminAuthMeResponse> {
  if (!inflightMe) {
    inflightMe = getAdminMe().finally(() => {
      inflightMe = null;
    });
  }

  return inflightMe;
}
