Files
otto/app/api/generate/route.ts
T
2026-07-08 19:17:05 +02:00

52 lines
1.5 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
const GenerateSchema = z.object({
destination: z.string().min(2),
startDate: z.string(),
numDays: z.number().int().min(1).max(14),
budget: z.number().positive(),
currency: z.string(),
experienceMode: z.string(),
preferences: z.array(z.string()),
});
export async function POST(req: NextRequest) {
try {
const body = await req.json();
const data = GenerateSchema.parse(body);
// Stub response (Phase 3 will replace with real Geoapify + LLM)
const days = Array.from({ length: data.numDays }, (_, i) => ({
day: i + 1,
activities: [
{
time: '09:30',
title: `Highlight ${i + 1} (${data.experienceMode})`,
type: data.experienceMode === 'foodie' ? 'restaurant' : 'attraction',
cost: Math.round(data.budget / (data.numDays * 3)),
},
{
time: '13:30',
title: 'Recommended meal',
type: 'restaurant',
cost: 22,
},
],
}));
return NextResponse.json({
tripId: 'trip_' + Date.now(),
destination: data.destination,
numDays: data.numDays,
experienceMode: data.experienceMode,
summary: `Stub plan for ${data.destination}${data.numDays} days in ${data.experienceMode} mode.`,
days,
estimatedCost: Math.round(data.budget * 0.82),
});
} catch (err) {
console.error(err);
return NextResponse.json({ error: 'Invalid input' }, { status: 400 });
}
}