import { triggerQueueProcessing } from "~/server/utils/queueProcessor";

export default defineEventHandler(async (event) => {
  try {
    // Get current user from auth middleware
    const user = event.context.user;
    if (!user) {
      throw createError({
        statusCode: 401,
        statusMessage: "Authentication required",
      });
    }

    console.log('🔄 Manually triggering queue processing...');

    // Trigger queue processing
    await triggerQueueProcessing();

    return {
      success: true,
      message: "Queue processing triggered successfully",
    };
  } catch (error) {
    console.error("Error triggering queue processing:", error);
    throw createError({
      statusCode: 500,
      statusMessage: "Failed to trigger queue processing",
      data: { error: error.message },
    });
  }
});
