import { prisma } from '@/lib/db';
import { agentGuard } from '@/lib/agentRoute';
/** { progress?: 0-100, message?: string, failed?: boolean, error?: string } */
export async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) {
  const bad = await agentGuard(req); if (bad) return bad;
  const { id } = await params;
  const b = await req.json();
  await prisma.order.update({ where: { id }, data: b.failed ? { status: 'FAILED', error: String(b.error || 'Harici üretim hatası').slice(0, 500) } : { progress: Math.max(0, Math.min(99, Number(b.progress) || 0)), progressMsg: b.message ? String(b.message).slice(0, 120) : undefined } });
  return Response.json({ ok: true });
}
