import { NextResponse } from 'next/server';

import { withAuth } from '@/lib/api/helpers';
import { parseQuery } from '@/lib/api/route-helpers';
import { errorResponse } from '@/lib/errors';
import { listNotificationsSchema } from '@/lib/validators/notifications';
import * as notificationsService from '@/lib/services/notifications.service';

export const GET = withAuth(async (req, ctx) => {
  try {
    const query = parseQuery(req, listNotificationsSchema);
    const result = await notificationsService.listNotifications(ctx.userId, ctx.portId, query);
    return NextResponse.json(result);
  } catch (error) {
    return errorResponse(error);
  }
});
