import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { errorResponse, ValidationError } from '@/lib/errors';
import { getInquiryById } from '@/lib/services/inquiries.service';

export const GET = withAuth(
  withPermission('inquiries', 'view', async (_req, ctx, params) => {
    try {
      const id = params.id;
      if (!id) throw new ValidationError('id is required');
      const data = await getInquiryById(id, ctx.portId);
      return NextResponse.json({ data });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
