import { NextRequest, NextResponse } from "next/server";
import prisma from "@/lib/db";
import { getSession } from "@/lib/auth";

export async function PUT(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
    const session = await getSession();
    if (!session) return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
    const { id } = await params;
    try {
        const { status } = await req.json();
        const quote = await prisma.quoteRequest.update({ where: { id }, data: { status } });
        return NextResponse.json(quote);
    } catch { return NextResponse.json({ error: "Erreur serveur" }, { status: 500 }); }
}

export async function DELETE(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
    const session = await getSession();
    if (!session) return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
    const { id } = await params;
    try {
        await prisma.quoteRequest.delete({ where: { id } });
        return NextResponse.json({ success: true });
    } catch { return NextResponse.json({ error: "Erreur serveur" }, { status: 500 }); }
}
