/**
 * RAG Status API
 * 
 * Returns the current state of the RAG system including
 * ingestion stats, document counts, and category breakdown.
 * 
 * GET /api/gfs/rag/status
 */

import { NextResponse } from 'next/server';
import { getRAGStatus, ingestBusinessDocuments } from '@/lib/gfs/rag';

export const dynamic = 'force-dynamic';

export async function GET() {
  try {
    // Ensure ingestion has run
    const ingestionResult = ingestBusinessDocuments();
    const status = getRAGStatus();

    return NextResponse.json({
      rag: {
        initialized: status.initialized,
        documents: status.stats.documents,
        totalChunks: status.stats.totalChunks,
        categories: status.stats.categories,
        lastIngestion: ingestionResult,
      },
    });
  } catch (error) {
    return NextResponse.json(
      { error: 'Failed to get RAG status' },
      { status: 500 }
    );
  }
}
