import { NextRequest, NextResponse } from "next/server"; export async function POST(req: NextRequest) { try { const body = await req.json() as { query: string; region: string; count: number }; const { query, region, count } = body; if (!query || typeof query !== "string") { return NextResponse.json({ error: "query is required" }, { status: 400 }); } const searchQuery = region ? `${query} ${region}` : query; const baseUrl = req.nextUrl.origin; const res = await fetch(`${baseUrl}/api/jobs/serp-enrich`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query: searchQuery, maxPages: Math.ceil((count || 50) / 10), countryCode: "de", languageCode: "de", filterSocial: true, categories: ["ceo"], enrichEmails: true, }), }); if (!res.ok) { const err = await res.json() as { error?: string }; return NextResponse.json({ error: err.error || "Failed to start job" }, { status: 500 }); } const data = await res.json() as { jobId: string }; return NextResponse.json({ jobId: data.jobId }); } catch (err) { console.error("POST /api/search error:", err); return NextResponse.json({ error: "Failed to start search" }, { status: 500 }); } }