import { NextRequest, NextResponse } from "next/server"; import { createOrder, listOrders, type OrderConfig } from "@/lib/orders-store"; // POST /api/orders (docs/04) — create a draft order from a configurator config. export async function POST(req: NextRequest) { let body: { flow?: string; config?: OrderConfig }; try { body = await req.json(); } catch { return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON" } }, { status: 400 }); } const flow = body.flow || "custom"; const config = body.config || {}; const order = await createOrder(flow, config); return NextResponse.json({ order_id: order.order_id, status: order.status, deposit_ore: order.deposit_ore, total_ore: order.total_ore }, { status: 201 }); } // GET /api/orders — list (org scoping added with auth). export async function GET() { const orders = await listOrders(); return NextResponse.json(orders); }