import { NextResponse } from "next/server" import { fetchMutation } from "convex/nextjs" import { api } from "@/convex/_generated/api" import { requireGhlSyncAuth } from "@/app/api/internal/ghl/shared" export async function POST(request: Request) { const authError = await requireGhlSyncAuth(request) if (authError) { return authError } try { const body = await request.json().catch(() => ({})) const result = await fetchMutation(api.crm.reconcileExternalState, { provider: body.provider ? String(body.provider) : "ghl", }) return NextResponse.json({ success: true, ...result, }) } catch (error) { console.error("Failed to reconcile mirrored external state:", error) return NextResponse.json( { error: "Failed to reconcile mirrored external state" }, { status: 500 } ) } }