import { NextRequest, NextResponse } from "next/server";

export const CORRELATION_ID_HEADER = "X-Correlation-Id";

export function getOrCreateCorrelationId(req: NextRequest): string {
  return req.headers.get(CORRELATION_ID_HEADER) ?? crypto.randomUUID();
}

export function withCorrelationId(response: NextResponse, correlationId: string): NextResponse {
  response.headers.set(CORRELATION_ID_HEADER, correlationId);
  return response;
}
