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

export async function GET(req: NextRequest) {
  const sessionId = new URL(req.url).searchParams.get('session_id')
  if (!sessionId) {
    return NextResponse.json({ order: null }, { status: 400 })
  }

  const order = await prisma.order.findUnique({
    where: { stripeSessionId: sessionId },
    select: {
      orderNumber: true,
      nom: true,
      cognoms: true,
      email: true,
      product: true,
      sizeTshirt: true,
      sizeSocks: true,
      shipping: true,
      totalAmount: true,
      status: true,
    },
  })

  return NextResponse.json({ order })
}
