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

export async function GET() {
  try {
    // Check admin count
    const adminCount = await db.admin.count();
    
    // Check polres count
    const polresCount = await db.polres.count();
    
    // Check polsek count
    const polsekCount = await db.polsek.count();
    
    // Get sample data
    const admins = await db.admin.findMany({
      select: {
        id: true,
        name: true,
        email: true,
        role: true,
        isActive: true
      }
    });
    
    const polresList = await db.polres.findMany({
      select: {
        id: true,
        name: true,
        address: true,
        isActive: true,
        order: true
      }
    });
    
    const polsekList = await db.polsek.findMany({
      select: {
        id: true,
        name: true,
        address: true,
        polresId: true,
        isActive: true,
        order: true
      }
    });

    return NextResponse.json({
      success: true,
      data: {
        adminCount,
        polresCount,
        polsekCount,
        admins,
        polresList,
        polsekList
      }
    });
  } catch (error) {
    console.error('Database check error:', error);
    return NextResponse.json({
      success: false,
      error: error.message
    }, { status: 500 });
  }
}