import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import type { AuthenticatedRequest, CurrentUser as ResolvedCurrentUser } from './auth-context.service';

export const CurrentUser = createParamDecorator(
  (_data: unknown, ctx: ExecutionContext): ResolvedCurrentUser | null => {
    const request = ctx.switchToHttp().getRequest<AuthenticatedRequest>();
    return request.currentUser ?? null;
  },
);
