import { SuggestionListQuerySchema } from '@nexumi/shared';
import { type NextRequest, NextResponse } from 'next/server';
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
import { listSuggestions } from '@/lib/module-configs/suggestions';

interface RouteParams {
  params: Promise<{ guildId: string }>;
}

export async function GET(request: NextRequest, { params }: RouteParams) {
  const { guildId } = await params;
  try {
    await requireGuildAccess(guildId);
    const searchParams = request.nextUrl.searchParams;
    const query = SuggestionListQuerySchema.parse({
      status: searchParams.get('status') ?? undefined,
      limit: searchParams.get('limit') ?? undefined
    });
    const suggestions = await listSuggestions(guildId, query);
    return NextResponse.json({ suggestions });
  } catch (error) {
    return toApiErrorResponse(error);
  }
}
