// src/pages/api/ai/queue-status.ts
import type { APIRoute } from 'astro';
import { getQueueStatus } from '../../../utils/rateLimitedQueue.js';
import { apiResponse, apiServerError } from '../../../utils/api.js';

export const prerender = false;

export const GET: APIRoute = async ({ request }) => {
  try {
    const url = new URL(request.url);
    const taskId = url.searchParams.get('taskId');
    
    const status = getQueueStatus(taskId || undefined);
    
    return apiResponse.success({
      ...status,
      timestamp: Date.now()
    });
  } catch (error) {
    console.error('Queue status error:', error);
    return apiServerError.internal('Failed to get queue status');
  }
};