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

export const CurrentTenant = createParamDecorator(
  (_data: unknown, ctx: ExecutionContext): string => {
    const request = ctx.switchToHttp().getRequest();
    const licenseId = request.user?.license_id;
    if (!licenseId) {
      throw new UnauthorizedException(
        'No license associated with this account. Create or join a server first.',
      );
    }
    return licenseId;
  },
);
