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

/**
 * 从请求中获取当前租户ID
 * 优先从 req.tenantId 获取，其次从 req.user.tenantId 获取
 */
export const CurrentTenantId = createParamDecorator(
  (data: unknown, ctx: ExecutionContext): number | undefined => {
    const request = ctx.switchToHttp().getRequest();
    return request.tenantId || request.user?.tenantId;
  },
);
