import { NextRequest, NextResponse } from 'next/server';
import { dbConnect } from '@/lib/dbConnect';
import { getStripeConfig } from '@/lib/stripe';

// GET /api/payments/config
// Returns public Stripe configuration (active publishable key and mode)
export async function GET(req: NextRequest) {
  try {
    await dbConnect();
    const config = await getStripeConfig();

    return NextResponse.json({
      success: true,
      stripe: {
        mode: config.mode,
        isEnabled: config.isEnabled,
        publishableKey: config.publishableKey,
      },
    });
  } catch (error: any) {
    return NextResponse.json(
      { success: false, error: error.message || 'Error fetching payment configuration' },
      { status: 500 }
    );
  }
}
