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

export default defineEventHandler(async (event) => {
  const user = await requireUser(event);
  const body = await readBody(event);

  const dbUpdates: Record<string, any> = {};
  if (body.username !== undefined) dbUpdates.username = body.username;
  if (body.nickname !== undefined) dbUpdates.nickname = body.nickname;
  if (body.avatar !== undefined) dbUpdates.avatar = body.avatar;

  if (Object.keys(dbUpdates).length > 0) {
    await updateProfile(user.id, dbUpdates);
  }

  return { success: true };
});
