// app/api/sync/workflow/action/route.ts import { NextRequest, NextResponse } from "next/server" import { workflowService } from "@/lib/vendor-document-list/workflow-service" import { getServerSession } from "next-auth" import { authOptions } from "@/app/api/auth/[...nextauth]/route" export async function POST(request: NextRequest) { try { const session = await getServerSession(authOptions) if (!session?.user?.id) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) } const body = await request.json() const { contractId, targetSystem = 'SWP', action, documents } = body if (!contractId || !action) { return NextResponse.json( { error: 'Contract ID and action are required' }, { status: 400 } ) } const result = await workflowService.executeWorkflowAction( contractId, targetSystem, action, documents || [], session.user.id, session.user.name ) return NextResponse.json(result) } catch (error) { console.error('Workflow action failed:', error) return NextResponse.json( { error: 'Workflow action failed', message: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ) } }