import { NextResponse } from 'next/server';

import { withAuth } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { getRecentSearches } from '@/lib/services/search.service';

export const GET = withAuth(async (_req, ctx) => {
  try {
    const searches = await getRecentSearches(ctx.userId, ctx.portId);
    return NextResponse.json({ searches });
  } catch (error) {
    return errorResponse(error);
  }
});
