import { NextResponse } from "next/server"; import { z } from "zod"; import { answerQuestion } from "@/lib/questions"; const questionSchema = z.object({ question: z.string().min(4).max(1200), language: z.enum(["DE", "EN"]).default("DE"), }); export async function POST(request: Request) { const parsed = questionSchema.safeParse(await request.json()); if (!parsed.success) { return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 }); } try { const answer = await answerQuestion(parsed.data.question, parsed.data.language); return NextResponse.json({ answer }); } catch (error) { return NextResponse.json( { error: error instanceof Error ? error.message : "Question answering failed" }, { status: 500 }, ); } }