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

export const dynamic = 'force-dynamic'

// Public endpoint — returns only the publishable key
export async function GET() {
  try {
    const keys = await (prisma as any).systemSetting.findMany({
      where: {
        key: { in: ['stripe_secret_key', 'stripe_public_key', 'stripe_webhook_secret'] },
      },
    })

    const secretKey = keys.find((k: any) => k.key === 'stripe_secret_key')?.value
    const publicKey = keys.find((k: any) => k.key === 'stripe_public_key')?.value

    if (!secretKey || !publicKey) {
      return NextResponse.json({ configured: false })
    }

    return NextResponse.json({ configured: true, publicKey })
  } catch (error: any) {
    console.error('[Stripe Config] Error:', error?.message || error)
    return NextResponse.json({ configured: false })
  }
}
