package com.tt.honeyDue.ui.components

/**
 * Shared camera-picker helpers (commonMain).
 *
 * The actual `rememberCameraPicker` composable lives at
 * `com.tt.honeyDue.platform.rememberCameraPicker` (expect/actual per
 * platform). This file captures the pure logic that decides *what* to do
 * when a user taps "Take photo" so it can be unit-tested without touching
 * the ActivityResult contract or iOS `UIImagePickerController`.
 *
 * Mirrors the iOS reference `CameraPickerView.swift`, which simply falls
 * back to the photo library if the camera source type is unavailable. On
 * Android we add a permission-rationale step to match Google's UX
 * guidelines, then delegate to the platform picker.
 */

/** The three possible outcomes of "user tapped Take photo". */
enum class CameraPermissionDecision {
    /** Camera permission already granted — launch the picker immediately. */
    Launch,

    /** Permission denied previously; show a rationale dialog before asking again. */
    ShowRationale,

    /** First request (or "don't ask again" cleared) — prompt the OS directly. */
    Request,
}

/**
 * Pure decision function: given the current permission state, return the
 * next UI action.
 *
 * @param isGranted `true` if the camera permission is currently held.
 * @param shouldShowRationale Android's `shouldShowRequestPermissionRationale`
 *   flag — `true` when the user has previously denied the permission but
 *   hasn't selected "don't ask again".
 */
fun decideCameraPermissionFlow(
    isGranted: Boolean,
    shouldShowRationale: Boolean,
): CameraPermissionDecision = when {
    isGranted -> CameraPermissionDecision.Launch
    shouldShowRationale -> CameraPermissionDecision.ShowRationale
    else -> CameraPermissionDecision.Request
}
