import { type NextRequest, NextResponse } from 'next/server';
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
import { listOpenTickets } from '@/lib/module-configs/tickets';

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

export async function GET(_request: NextRequest, { params }: RouteParams) {
  const { guildId } = await params;
  try {
    await requireGuildAccess(guildId);
    const tickets = await listOpenTickets(guildId);
    return NextResponse.json({ tickets });
  } catch (error) {
    return toApiErrorResponse(error);
  }
}
