import { prisma } from '@/lib/db';
import { agentGuard } from '@/lib/agentRoute';
export const dynamic = 'force-dynamic';
/** Bekleyen (ödenmiş, sahiplenilmemiş) siparişleri render spesifikasyonuyla listeler. GET imzası: `${ts}.${path+query}` */
export async function GET(req: Request) {
  const bad = await agentGuard(req); if (bad) return bad;
  const orders = await prisma.order.findMany({ where: { status: { in: ['PAID', 'QUEUED'] }, claimedBy: null }, orderBy: { createdAt: 'asc' }, take: 50 });
  return Response.json(orders.map((o) => ({
    id: o.id, code: o.code, status: o.status, template: o.template, voice: o.voice, quality: o.quality, createdAt: o.createdAt,
    parcel: { il: o.il, ilce: o.ilce, mahalle: o.mahalle, mahalleId: o.mahalleId, ada: o.ada, parsel: o.parsel },
    imar: { durum: o.imarDurum, emsal: o.emsal, taks: o.taks, gabari: o.gabari }, highlights: o.highlights, headline: o.headline,
    contact: { name: o.contactName, phone: o.contactPhone }, aiCloseups: o.aiCloseups,
    sale: { type: o.saleType, unitType: o.unitType, unitArea: o.unitArea, rooms: o.rooms, floor: o.floorNo, buildYear: o.buildYear, share: o.share, target: o.targetLon != null && o.targetLat != null ? [o.targetLon, o.targetLat] : null },
  })));
}
