export const dynamic = 'force-dynamic';

import { NextResponse } from 'next/server';
import { requireDFAuth } from '@/lib/dark-factory/auth-guard';
import { getRouterStats } from '@/lib/dark-factory/rag/router';
import { getCacheStats } from '@/lib/dark-factory/rag/token-conservation';

export async function GET() {
  const authResult = await requireDFAuth();
  if (!authResult.authorized) return authResult.response;

  const routerStats = getRouterStats();
  const cacheStats = getCacheStats();

  return NextResponse.json({
    version: routerStats.version,
    cache: {
      size: cacheStats.size,
      totalHits: cacheStats.totalHits,
      totalSaved: cacheStats.totalSaved,
    },
  });
}
