// src/pages/api/ai/embeddings-status.ts
import type { APIRoute } from 'astro';

export const prerender = false;

export const GET: APIRoute = async () => {
  try {
    const { embeddingsService } = await import('../../../utils/embeddings.js');
    await embeddingsService.waitForInitialization();
    
    const stats = embeddingsService.getStats();
    const status = stats.enabled && stats.initialized ? 'ready' : 
                  stats.enabled && !stats.initialized ? 'initializing' : 'disabled';
    
    return new Response(JSON.stringify({
      success: true,
      embeddings: stats,
      timestamp: new Date().toISOString(),
      status: status
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' }
    });
    
  } catch (error) {
    return new Response(JSON.stringify({
      success: false,
      embeddings: { enabled: false, initialized: false, count: 0 },
      timestamp: new Date().toISOString(),
      status: 'disabled',
      error: error.message
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' }
    });
  }
};