import { NextRequest, NextResponse } from "next/server";
import { pushCardToMonday } from "@/lib/integrations";
import { requireApiAuth, handleApiError } from "@/lib/api-auth";

export async function POST(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    await requireApiAuth();
    const { id } = await params;
    const result = await pushCardToMonday(id);
    return NextResponse.json({
      ok: true,
      action: result.action,
      mondayItemId: result.mondayItemId,
    });
  } catch (error) {
    return handleApiError(error);
  }
}
