export interface IdempotentCommand<T> {
  readonly idempotencyKey: string
  readonly request: T
}

export function createIdempotencyKey(): string {
  return crypto.randomUUID()
}

/**
 * Create once per user intent. Retries must reuse the returned envelope rather than call this again.
 */
export function createIdempotentCommand<T>(request: T): IdempotentCommand<T> {
  return Object.freeze({ idempotencyKey: createIdempotencyKey(), request })
}
