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

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