import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import { z } from "zod";

const schema = z.object({ name: z.string().min(1), category: z.string().min(1), latitude: z.coerce.number(), longitude: z.coerce.number(), address: z.string().optional(), contact: z.string().optional() });

export async function POST(req: Request) {
  const body = await req.json().catch(() => ({}));
  const parsed = schema.safeParse(body);
  if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
  const created = await prisma.partnerRequest.create({ data: parsed.data });
  return NextResponse.json({ request: created }, { status: 201 });
}

export async function GET() {
  const items = await prisma.partnerRequest.findMany({ orderBy: { createdAt: "desc" } });
  return NextResponse.json({ requests: items });
}


