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

export const prerender = false;

export const GET: APIRoute = async () => {
  try {
    await embeddingsService.waitForInitialization();
    
    const stats = embeddingsService.getStats();
    const status = stats.initialized ? 'ready' : 
                  !stats.initialized ? 'initializing' : 'disabled';
    
    console.log(`[EMBEDDINGS-STATUS-API] Service status: ${status}, stats:`, stats);
    
    return new Response(JSON.stringify({
      success: true,
      embeddings: stats,
      timestamp: new Date().toISOString(),
      status: status
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' }
    });
    
  } catch (error) {
    console.error('[EMBEDDINGS-STATUS-API] Error checking embeddings status:', 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' }
    });
  }
};