import { NextResponse } from 'next/server';

import { withAuth } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { getActiveConnections } from '@/lib/services/system-monitoring.service';

export const GET = withAuth(async (_req, ctx) => {
  try {
    if (!ctx.isSuperAdmin) {
      return NextResponse.json({ error: 'Insufficient permissions' }, { status: 403 });
    }

    const connections = await getActiveConnections();
    return NextResponse.json({ data: connections });
  } catch (error) {
    return errorResponse(error);
  }
});
