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

export interface AuthUser {
  sub: string;
  username: string;
  tenantId?: string | null;
  roles: string[];
  permissions: string[];
  regionIds: string[];
}

export const CurrentUser = createParamDecorator((data: keyof AuthUser | undefined, ctx: ExecutionContext) => {
  const request = ctx.switchToHttp().getRequest<Request & { user?: AuthUser }>();
  const user = request.user;
  return data && user ? user[data] : user;
});
