import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { getRestoreDossier } from '@/lib/services/client-restore.service';
import { errorResponse, NotFoundError } from '@/lib/errors';

export const GET = withAuth(
  withPermission('clients', 'edit', async (_req, ctx, params) => {
    try {
      const id = params.id;
      if (!id) throw new NotFoundError('client');
      const dossier = await getRestoreDossier(id, ctx.portId);
      return NextResponse.json({ data: dossier });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
