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

/**
 * @TenantId() — parameter decorator to extract tenant_id from request.
 *
 * Usage in controllers:
 *   @Get()
 *   findAll(@TenantId() tenantId: string) { ... }
 *
 * Per CLAUDE.md: Controllers should NOT use this to pass tenant_id
 * to services. It exists only for edge cases where tenant context
 * is needed directly (e.g., logging, audit).
 */
export const TenantId = createParamDecorator(
  (_data: unknown, ctx: ExecutionContext): string => {
    const request = ctx.switchToHttp().getRequest();
    return request.tenantId;
  },
);
