export interface IdempotencyKeyRef {
  current: string | null;
}

export function getActionIdempotencyKey(
  ref: IdempotencyKeyRef,
  create: () => string = () => crypto.randomUUID(),
): string {
  ref.current ??= create();
  return ref.current;
}

export function resetActionIdempotencyKey(ref: IdempotencyKeyRef): void {
  ref.current = null;
}
