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

// GET - List active payment gateways (public, for checkout page)
export async function GET() {
  try {
    const gateways = await db.paymentGateway.findMany({
      where: { isActive: true },
      orderBy: [{ sortOrder: 'asc' }, { createdAt: 'desc' }],
      select: {
        id: true,
        name: true,
        slug: true,
        type: true,
        icon: true,
        description: true,
        instructions: true,
        sortOrder: true,
      },
    });

    return NextResponse.json({ success: true, gateways });
  } catch (error) {
    console.error('Active payment gateways fetch error:', error);
    return NextResponse.json({ success: false, error: 'Failed to fetch payment gateways' }, { status: 500 });
  }
}
