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

const schema = z.object({ name: z.string().min(1), contact: z.string().min(1), category: z.string().optional(), message: z.string().min(1) });

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.partnerInquiry.create({ data: parsed.data });
  return NextResponse.json({ inquiry: created }, { status: 201 });
}

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


