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

export interface TenantScopeContext {
  hostId: string;
  tenantId: string;
  clinicIds: string[];
  userId: string;
}

export const TenantScope = createParamDecorator(
  (_data: unknown, ctx: ExecutionContext): TenantScopeContext => {
    const req = ctx.switchToHttp().getRequest<{ tenantScope?: TenantScopeContext }>();
    if (!req.tenantScope) {
      throw new Error('TenantScope used on unauthenticated route');
    }
    return req.tenantScope;
  },
);
