/**
 * POST /api/me/presence-visibility
 *
 * Opt-out toggle for the authenticated user's online status visibility.
 * When visible=false, no other user will see lastSeenAt regardless of follow status.
 *
 * Body:   { visible: boolean }
 * Response: { presenceVisible: boolean }
 */
import { requireUser } from "../../utils/auth";
import { setPresenceVisible } from "../../db/profile";

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

  const body = await readBody(event);
  if (typeof body?.visible !== "boolean") {
    throw createError({ statusCode: 400, message: "INVALID_VISIBLE" });
  }

  const result = await setPresenceVisible(user.id, body.visible);
  return result;
});
