import { createParamDecorator, type ExecutionContext } from '@nestjs/common';
import type { Request } from 'express';

/**
 * Decorator to extract restId from the authenticated request.
 * Must be used after AdminAuthGuard or AuthGuard that sets request.restId.
 *
 * @example
 * @Get('/restaurants')
 * @UseGuards(AdminAuthGuard)
 * getRestaurants(@RestId() restId: string) {
 *   return this.restaurantService.findById(restId);
 * }
 */
export const RestId = createParamDecorator((data: unknown, ctx: ExecutionContext): string => {
  const request = ctx.switchToHttp().getRequest<Request & { restId?: string }>();
  return request.restId || '';
});
