import { NextResponse } from 'next/server';
import { withErrorHandler, RouteContext } from '@server/middleware/withErrorHandler';
import { withAuth, AuthedRequest } from '@server/middleware/withAuth';
import { revokeApiKey } from '@server/services/api-keys.service';

export const DELETE = withErrorHandler(
  withAuth(async (req: AuthedRequest, ctx: RouteContext) => {
    const { id } = await ctx.params;
    const { restaurantId } = req.session;
    const key = await revokeApiKey(id, restaurantId!);
    return NextResponse.json({ key });
  })
);
