import { NextResponse } from 'next/server';

import { type RouteHandler } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { rollbackToVersion } from '@/lib/services/berth-pdf.service';

export const postHandler: RouteHandler = async (_req, ctx, params) => {
  try {
    const result = await rollbackToVersion(params.id!, params.versionId!, ctx.portId);
    return NextResponse.json({ data: result });
  } catch (error) {
    return errorResponse(error);
  }
};
