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

// GET /api/produits/[id]/images - Get all images for a product
export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    const { id } = await params
    const images = await db.fichier.findMany({
      where: {
        produitId: id,
        type: 'IMAGE_PRODUIT',
      },
      orderBy: {
        createdAt: 'desc',
      },
    })

    return NextResponse.json(images)
  } catch (error) {
    console.error('Error fetching product images:', error)
    return NextResponse.json(
      { error: 'Failed to fetch images' },
      { status: 500 }
    )
  }
}
