import { NextRequest, NextResponse } from "next/server"
import prisma from "@/lib/prisma"

export async function POST(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    if (!prisma) {
      return NextResponse.json({ error: "Database not configured" }, { status: 503 })
    }
    const { id } = await params
    
    if (id.startsWith("demo-")) {
      return NextResponse.json({ ok: true })
    }

    await prisma.pledge.update({
      where: { id },
      data: {
        status: "initiated",
        iPaidClickedAt: new Date(),
      },
    })

    return NextResponse.json({ ok: true })
  } catch (error) {
    console.error("Mark initiated error:", error)
    return NextResponse.json({ error: "Internal error" }, { status: 500 })
  }
}
