import { serializeOperationMetadata } from "@open-mercato/shared/lib/commands/operationMetadata";
function attachOperationMetadataHeader(response, logEntry, fallback = {}) {
  if (!logEntry?.undoToken || !logEntry.id || !logEntry.commandId) return;
  const executedAt = logEntry.createdAt instanceof Date ? logEntry.createdAt.toISOString() : typeof logEntry.createdAt === "string" && logEntry.createdAt.trim().length > 0 ? logEntry.createdAt : (/* @__PURE__ */ new Date()).toISOString();
  response.headers.set(
    "x-om-operation",
    serializeOperationMetadata({
      id: logEntry.id,
      undoToken: logEntry.undoToken,
      commandId: logEntry.commandId,
      actionLabel: logEntry.actionLabel ?? null,
      resourceKind: logEntry.resourceKind ?? fallback.resourceKind ?? null,
      resourceId: logEntry.resourceId ?? fallback.resourceId ?? null,
      executedAt
    })
  );
}
export {
  attachOperationMetadataHeader
};
//# sourceMappingURL=operationMetadata.js.map
