import { cancelQueuedLeg, performAction } from '@/lib/game/actions'; // POST /api/planes/:planeId/queue/cancel (v0.25.0, ISS-043) — body { index: number }. // Removes a NOT-yet-started leg from the plane's queue by index; only queued legs // are cancellable, the active in-flight leg is never affected. 400 missing/ // non-integer index, unknown fields, or an index outside [0, queue.length); 404 // unknown plane id. On success returns the full state snapshot (plane.queue updated). export async function POST(req: Request, ctx: { params: Promise<{ planeId: string }> }) { const { planeId } = await ctx.params; let body: unknown; try { const text = await req.text(); body = text ? JSON.parse(text) : {}; } catch { return Response.json({ error: 'invalid JSON body' }, { status: 400 }); } if (typeof body !== 'object' || body === null || Array.isArray(body)) { return Response.json({ error: 'body must be a JSON object' }, { status: 400 }); } const input = body as Record; for (const key of Object.keys(input)) { if (key !== 'index') { return Response.json({ error: `unknown field "${key}"` }, { status: 400 }); } } if (!Number.isInteger(input.index)) { return Response.json({ error: 'index must be an integer' }, { status: 400 }); } const index = input.index as number; return performAction((inst) => cancelQueuedLeg(inst, planeId, index)); }