import { NextResponse } from 'next/server';

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

// GET /api/v1/berths/options - lightweight list for selects/comboboxes
export const GET = withAuth(
  withPermission('berths', 'view', async (req, ctx) => {
    try {
      const options = await getBerthOptions(ctx.portId);
      return NextResponse.json({ data: options });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
