import { NextResponse } from "next/server";
import { db } from "@/db";
import { leads } from "@/db/schema";

export async function POST(req: Request) {
  try {
    const body = await req.json();
    const [lead] = await db
      .insert(leads)
      .values({
        patientName: body.name,
        country: body.country || "Bangladesh",
        treatment: body.treatment || "General Inquiry",
        status: "new",
        nextAction: "Initial consultation",
        email: body.email,
        phone: body.phone,
        notes: body.message,
        preferredMonth: body.preferredMonth,
      })
      .returning();
    return NextResponse.json({ success: true, id: lead.id }, { status: 201 });
  } catch (error) {
    return NextResponse.json({ error: String(error) }, { status: 500 });
  }
}
