export type MediaKind = 'photo' | 'video'

/** Raw output of a picker or camera, before the resize/compress pipeline runs. */
export type RawAsset = {
  uri: string
  kind: MediaKind
  mimeType: string
  width?: number
  height?: number
  /** Video duration in milliseconds. */
  durationMs?: number
  /** Byte size when the picker reported it — filled in by processors otherwise. */
  size?: number
}

/** Post-processed, ready-to-upload asset with user-supplied metadata. */
export type MediaAsset = RawAsset & {
  altText: string | null
  /** Set when processing produced a different file than what the user picked. */
  originalUri?: string
}

export type PickOptions = {
  /** Which media types the picker should allow. */
  kinds: MediaKind[]
  multiple?: boolean
  /** Max selections when `multiple` is true. */
  limit?: number
  /** Show the native edit UI with a 1:1 aspect ratio (avatars, tight crops). */
  squareCrop?: boolean
  /** `ordered` preserves selection order on iOS; defaults to true. */
  ordered?: boolean
  /** Use the older iOS image picker UI. Leave undefined to use the modern one. */
  legacy?: boolean
}

export type ProcessOptions = {
  /** Bytes at which photos get resized down. Default 5 MB. */
  maxImageBytes?: number
  /** Longest-edge target width after resize. Default 4096. */
  maxImageWidth?: number
  /** Encoder quality for the resized/transcoded output (0..1). Default 0.85.
   *  Honoured by both JPEG and WebP. */
  imageQuality?: number
  /** The destination instance's `media_attachments.supported_mime_types` list.
   *  Pass through from `useInstanceCapabilities()` so resize/transcode picks
   *  WebP when the server accepts it (smaller files, native Mastodon support)
   *  and JPEG otherwise. Null/undefined → conservative JPEG fallback. */
  supportedImageMimeTypes?: string[] | null
  /** Server-enforced video byte cap. REQUIRED. */
  maxVideoBytes: number
  /** Force MP4 remux for non-mp4 sources. Default true. */
  forceMp4?: boolean
  onVideoProgress?: (fraction: number) => void
  signal?: AbortSignal
  /** Hard cap on compression time in ms. Default 120s. */
  videoTimeoutMs?: number
}

/** Shape we post to `/api/v2/media`. iOS strips the `file://` prefix. */
export type UploadFile = {
  uri: string
  type: string
  name: string
}
