import { NextResponse } from 'next/server';

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

export const POST = withAuth(async (_req, ctx) => {
  try {
    requireSuperAdmin(ctx, 'currency.rates.refresh');

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