import { NextResponse } from 'next/server';
import { withErrorHandler } from '@server/middleware/withErrorHandler';
import { withAuth } from '@server/middleware/withAuth';
import { syncOpenRouterModels } from '@server/services/openrouter-sync.service';

export const POST = withErrorHandler(
  withAuth(async () => {
    const result = await syncOpenRouterModels();
    if (result.error) {
      return NextResponse.json({ success: false, ...result }, { status: 502 });
    }
    return NextResponse.json({ success: true, ...result });
  })
);
