import { NextResponse } from 'next/server';

import { withAuth } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { refreshRates } from '@/lib/services/currency';

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

    await refreshRates();
    return NextResponse.json({ data: { success: true } });
  } catch (error) {
    return errorResponse(error);
  }
});
