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

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