import { usePrisma } from "../../utils/prisma";
import { requireUser } from "../../utils/auth";

/**
 * GET /api/magic/me
 *
 * Profil-Info des eingeloggten Magic-Users f\u00fcr den Hub-Header.
 * Response: { nickname, avatar, plan }
 */
export default defineEventHandler(async (event) => {
  const user = await requireUser(event);
  const db = usePrisma();

  const profile = await db.profile.findUnique({
    where: { id: user.id },
    select: { nickname: true, username: true, avatar: true, plan: true },
  });

  return {
    success: true,
    data: {
      nickname: profile?.nickname ?? profile?.username ?? null,
      avatar: profile?.avatar ?? null,
      plan: profile?.plan ?? null,
    },
  };
});
