import {
  hasLotteryAdminApiBaseUrl,
  publicAdminRequest,
} from "@/lib/admin-http";
import type {
  AdminAuthCaptchaResponse,
  AdminAuthLoginRequest,
  AdminAuthLoginResponse,
  AdminAuthMeResponse,
} from "@/types/api/admin-auth";
import { adminRequest } from "@/lib/admin-http";


/** `GET /api/v1/admin/auth/captcha`（无需 Token） */
export async function getAdminCaptcha(): Promise<AdminAuthCaptchaResponse | null> {
  if (!hasLotteryAdminApiBaseUrl()) {
    return null;
  }
  try {
    return await publicAdminRequest<AdminAuthCaptchaResponse>({
      url: `/admin/auth/captcha`,
      method: "GET",
    });
  } catch {
    return null;
  }
}

/** `POST /api/v1/admin/auth/login`（无需 Token） */
export async function postAdminLogin(
  body: AdminAuthLoginRequest,
): Promise<AdminAuthLoginResponse> {
  return publicAdminRequest<AdminAuthLoginResponse>({
    url: `/admin/auth/login`,
    method: "POST",
    data: body,
  });
}

/** `GET /api/v1/admin/auth/me`（需 Token） */
export async function getAdminMe(): Promise<AdminAuthMeResponse> {
  return adminRequest.get<AdminAuthMeResponse>(`/admin/auth/me`);
}
