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

/**
 * Decorator para obtener el tenant_id del usuario actual.
 * Atajo conveniente para @CurrentUser('tenantId').
 *
 * @example
 * @Get()
 * async findAll(@CurrentTenant() tenantId: string) {
 *   return this.clientService.findAllByTenant(tenantId);
 * }
 */
export const CurrentTenant = createParamDecorator(
  (data: unknown, ctx: ExecutionContext): string => {
    const request = ctx.switchToHttp().getRequest();
    return request.user?.tenantId;
  },
);
