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

const contactSchema = z.object({
  name: z.string().min(2),
  company: z.string().min(2),
  email: z.email(),
  phone: z.string().min(6),
  projectType: z.string().min(2),
  message: z.string().min(10),
  utm_source: z.string().optional(),
  utm_medium: z.string().optional(),
  utm_campaign: z.string().optional()
});

export async function POST(request: Request) {
  const body = await request.json().catch(() => null);
  const result = contactSchema.safeParse(body);

  if (!result.success) {
    return NextResponse.json({ ok: false, errors: result.error.flatten() }, { status: 400 });
  }

  return NextResponse.json({
    ok: true,
    mode: process.env.CONTACT_DELIVERY_MODE ?? "placeholder",
    message: "Talk to Akarya inquiry validated. Connect this route to email, CRM, or database in production."
  });
}
