import { performAction, sellPlane } from '@/lib/game/actions'; // POST /api/market/sell-plane (v0.8.0) — body { planeId: string }. Sells a grounded // plane for 50% of its catalog price and deletes the row. 400 missing/non-string // planeId or unknown fields; 404 unknown id; 409 if the plane is flying or it is // the last remaining plane. On success returns the full state snapshot. export async function POST(req: Request) { 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 !== 'planeId') { return Response.json({ error: `unknown field "${key}"` }, { status: 400 }); } } if (typeof input.planeId !== 'string' || input.planeId.length === 0) { return Response.json({ error: 'planeId must be a non-empty string' }, { status: 400 }); } const planeId = input.planeId; return performAction(req, (inst, playerId) => sellPlane(inst, planeId, playerId)); }