import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { getMergeFields } from '@/lib/services/document-templates';

export const GET = withAuth(
  withPermission('documents', 'view', async (_req, _ctx) => {
    try {
      const mergeFields = getMergeFields();
      return NextResponse.json({ data: mergeFields });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
