export interface R2HttpMetadata {
  contentType?: string
  cacheControl?: string
}

export interface R2PutOptions {
  httpMetadata?: R2HttpMetadata
  customMetadata?: Record<string, string>
}

export interface R2PutResult {
  key: string
  size: number
  etag: string
}

export interface R2PutBucket {
  put(
    key: string,
    value: ReadableStream | ArrayBuffer | ArrayBufferView | string | null | Blob,
    options?: R2PutOptions,
  ): Promise<R2PutResult>
}

/** Thin adapter over the native Workers `R2Bucket.put` binding. */
export async function putObject(
  bucket: R2PutBucket,
  key: string,
  body: ReadableStream | ArrayBuffer | ArrayBufferView | string | null | Blob,
  opts?: R2PutOptions,
): Promise<R2PutResult> {
  return bucket.put(key, body, opts)
}
