import { getApprovalRequest } from "../../../db/device-approvals";

/**
 * GET /api/devices/approvals/:id
 *
 * Status-Poll für das NEUE Gerät während es darauf wartet dass ein anderes
 * Gerät / Email-Link approved. skipDeviceCheck=true.
 *
 * Frontend pollt alle 2-3s oder via realtime-subscription.
 */
export default defineEventHandler(async (event) => {
  const user = await requireUser(event, { skipDeviceCheck: true });
  const id = getRouterParam(event, "id");
  if (!id) {
    throw createError({ statusCode: 400, message: "id required" });
  }
  const approval = await getApprovalRequest(id, user.id);
  if (!approval) {
    throw createError({ statusCode: 404, message: "approval not found" });
  }
  return { approval };
});
