package com.tt.honeyDue.util

/**
 * Cross-platform image compression matching the iOS helper
 * `iosApp/iosApp/Helpers/ImageCompression.swift`.
 *
 * Contract:
 * - Input is a raw encoded-image [ByteArray] (JPEG, PNG, HEIC…).
 * - Output is a JPEG-encoded [ByteArray] at [quality] (default 0.7), with
 *   the long edge clamped to [maxEdgePx] (default 1920px) while preserving
 *   aspect ratio.
 * - EXIF orientation is applied into the pixel data; the output image is
 *   always in the canonical "upright" orientation (no orientation tag, or
 *   `ORIENTATION_NORMAL`).
 *
 * Platforms:
 * - Android → `BitmapFactory` + `ExifInterface` + `Matrix` + JPEG compress.
 * - iOS → `UIImage(data:)` + `UIImage.jpegData(compressionQuality:)`.
 *   `UIImage` normalizes EXIF automatically during decode.
 * - JVM / JS / WASM → no-op pass-through (web/desktop do not run this path
 *   in production; returning the input keeps common code simple).
 *
 * This replaces the size-capped `ImageCompressor` helper for new call sites
 * that want to match iOS (quality-based, not size-based) semantics.
 */
expect object ImageCompression {
    /**
     * Compress [input] to JPEG, optionally downscaling.
     *
     * @param input encoded image bytes (JPEG/PNG/HEIC supported by the platform).
     * @param maxEdgePx maximum long-edge size in pixels (aspect preserved).
     *                  Defaults to `1920` to match iOS.
     * @param quality JPEG quality in `[0.0f, 1.0f]`. Defaults to `0.7f` to match iOS.
     * @return compressed JPEG bytes, or the original input on decode failure.
     */
    suspend fun compress(
        input: ByteArray,
        maxEdgePx: Int = 1920,
        quality: Float = 0.7f
    ): ByteArray
}
