import { NextResponse } from 'next/server';
import { prisma } from '@/lib/db';

export const runtime = 'nodejs';

export async function GET() {
  try {
    // Get bible statistics
    const [
      totalBibleVersions,
      totalVerses,
      totalBooks
    ] = await Promise.all([
      // Count total Bible versions
      prisma.bibleVersion.count(),

      // Count total verses across all versions
      prisma.bibleVerse.count(),

      // Count unique books (66 biblical books)
      prisma.bibleBook.groupBy({
        by: ['bookKey'],
      }).then(result => result.length)
    ]);

    return NextResponse.json({
      bibleVersions: totalBibleVersions,
      verses: totalVerses,
      books: totalBooks
    });

  } catch (error) {
    console.error('Stats API error:', error);
    return NextResponse.json(
      { error: 'Failed to fetch statistics' },
      { status: 500 }
    );
  }
}