import { NextResponse } from 'next/server';
import { withErrorHandler } from '@server/middleware/withErrorHandler';
import { withAuth, AuthedRequest } from '@server/middleware/withAuth';
import { listDeliveryLogs } from '@server/services/webhooks.service';

export const GET = withErrorHandler(
  withAuth(async (req: AuthedRequest) => {
    const { searchParams } = new URL(req.url);
    const webhookId = searchParams.get('webhook_id') ?? undefined;
    const logs = await listDeliveryLogs(req.session.restaurantId!, webhookId);
    return NextResponse.json({ logs });
  })
);
