import { toggleChatMessageLike, toggleDmLike } from "../../db/chat-rooms";

/** POST /api/chat/like – Toggle Like auf Chat-Message oder DM */
export default defineEventHandler(async (event) => {
  const user = await requireUser(event);
  const body = await readBody(event);

  const messageId = body?.messageId;
  const type = body?.type; // "chat" | "dm"

  if (!messageId || !type) {
    throw createError({ statusCode: 400, message: "messageId und type erforderlich" });
  }

  let liked: boolean;
  if (type === "dm") {
    liked = await toggleDmLike(user.id, messageId);
  } else {
    liked = await toggleChatMessageLike(user.id, messageId);
  }

  return { liked };
});
