import { getProfile } from "../../db/profile";

export default defineEventHandler(async (event) => {
  const user = await requireUser(event);
  const dbProfile = await getProfile(user.id);

  return {
    id: user.id,
    email: user.email,
    username: dbProfile?.username ?? "",
    nickname: dbProfile?.nickname ?? null,
    avatar: dbProfile?.avatar ?? null,
    plan: (dbProfile?.plan === "premium"
      ? "legend"
      : dbProfile?.plan === "standard"
        ? "pro"
        : dbProfile?.plan ?? "free") as "free" | "pro" | "legend",
    streak: dbProfile?.streak ?? 0,
    created_at: dbProfile?.createdAt?.toISOString() ?? user.created_at,
  };
});
