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

// GET /api/pos/products - Get all active products
export async function GET(request: NextRequest) {
  try {
    const products = await db.produit.findMany({
      where: {
        actif: true,
        stock: {
          gt: 0
        }
      },
      orderBy: {
        designation: 'asc'
      }
    })

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