/**
 * POST /api/me/calls-enabled
 *
 * Opt-out toggle für eingehende Voice-Calls des authentifizierten Users.
 * calls_enabled=false → andere User können nicht anrufen (zusätzlich zur
 * Mutual-Follow-Schranke). Default true.
 *
 * Body:     { enabled: boolean }
 * Response: { callsEnabled: boolean }
 */
import { requireUser } from "../../utils/auth";
import { setCallsEnabled } from "../../db/profile";

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

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

  return setCallsEnabled(user.id, body.enabled);
});
