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

// GET /api/interviews
export async function GET() {
    try {
        const interviews = await prisma.interview.findMany({
            orderBy: { date: 'desc' },
        })
        return NextResponse.json(interviews)
    } catch (error) {
        console.error('GET /api/interviews error:', error)
        return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
    }
}

// POST /api/interviews
export async function POST(request: NextRequest) {
    try {
        const body = await request.json()
        const interview = await prisma.interview.create({ data: body })
        return NextResponse.json(interview, { status: 201 })
    } catch (error) {
        console.error('POST /api/interviews error:', error)
        return NextResponse.json({ error: 'Erreur lors de la création' }, { status: 500 })
    }
}
