import { NextRequest, NextResponse } from 'next/server' import { getServerSession } from 'next-auth' import { authOptions } from '@/lib/auth' import { prisma } from '@/lib/prisma' export async function POST(req: NextRequest, { params }: { params: { id: string } }) { const session = await getServerSession(authOptions) if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) const queue = await prisma.smsQueue.findUnique({ where: { id: params.id } }) if (!queue) return NextResponse.json({ error: 'Not found' }, { status: 404 }) await prisma.smsQueue.update({ where: { id: params.id }, data: { status: 'PENDING', attempts: 0, lastError: null, scheduledAt: new Date() }, }) // Trigger processing fetch(`${process.env.NEXTAUTH_URL}/api/queue/process`, { method: 'POST', headers: { 'x-internal-key': process.env.INTERNAL_API_KEY || '' }, }).catch(() => {}) return NextResponse.json({ success: true, message: 'Queued for retry' }) }