// app/api/sync/workflow/status/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 GET(request: NextRequest) { try { const session = await getServerSession(authOptions) if (!session?.user?.id) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) } const { searchParams } = new URL(request.url) const contractId = searchParams.get('contractId') const targetSystem = searchParams.get('targetSystem') || 'SWP' if (!contractId) { return NextResponse.json( { error: 'Contract ID is required' }, { status: 400 } ) } const status = await workflowService.getWorkflowStatus( Number(contractId), targetSystem ) return NextResponse.json(status) } catch (error) { console.error('Failed to get workflow status:', error) return NextResponse.json( { error: 'Failed to get workflow status', message: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ) } }