// apps/admin/server/api/admin/lyra-profile.get.ts
//
// Proxy: holt Nickname + Avatar des Lyra- bzw. ReBreak-Bot-Accounts.
// Admin-Secret bleibt server-only (NIE im Client-Bundle).

export default defineEventHandler(async (event): Promise<{ nickname: string; avatar: string | null }> => {
  const config = useRuntimeConfig();
  const apiBase = config.public.apiBase;
  const adminSecret = config.adminSecret;

  if (!adminSecret) {
    throw createError({
      statusCode: 500,
      statusMessage: "ADMIN_SECRET nicht konfiguriert (Infisical-Var fehlt)",
    });
  }

  const query = getQuery(event);

  try {
    return await $fetch(`${apiBase}/api/admin/lyra-profile`, {
      method: "GET",
      headers: { "x-admin-secret": adminSecret },
      query,
    });
  } catch (err: any) {
    throw createError({
      statusCode: err?.statusCode ?? 502,
      statusMessage:
        err?.statusMessage ?? err?.message ?? "Backend-Request fehlgeschlagen",
    });
  }
});
