import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { listDocumentSigners } from '@/lib/services/documents.service';

export const GET = withAuth(
  withPermission('documents', 'view', async (req, ctx, params) => {
    try {
      const signers = await listDocumentSigners(params.id!, ctx.portId);
      return NextResponse.json({ data: signers });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
