package com.tt.honeyDue.util

import com.tt.honeyDue.ui.components.CameraPermissionDecision
import com.tt.honeyDue.ui.components.decideCameraPermissionFlow
import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Pure-logic tests for the camera-permission decision function used by
 * [CameraPicker].
 *
 * The function decides what to do when the user taps "Take photo":
 *   - already granted           → [CameraPermissionDecision.Launch]
 *   - denied but rationale shown → [CameraPermissionDecision.ShowRationale]
 *   - hard-denied / never asked  → [CameraPermissionDecision.Request]
 *
 * UI for the actual dialog + launcher is exercised manually; this isolates
 * the branching logic so regressions are caught by unit tests.
 */
class CameraPermissionStateTest {

    @Test
    fun granted_leadsToLaunch() {
        val decision = decideCameraPermissionFlow(
            isGranted = true,
            shouldShowRationale = false
        )
        assertEquals(CameraPermissionDecision.Launch, decision)
    }

    @Test
    fun notGranted_withRationale_leadsToShowRationale() {
        val decision = decideCameraPermissionFlow(
            isGranted = false,
            shouldShowRationale = true
        )
        assertEquals(CameraPermissionDecision.ShowRationale, decision)
    }

    @Test
    fun notGranted_withoutRationale_leadsToRequest() {
        val decision = decideCameraPermissionFlow(
            isGranted = false,
            shouldShowRationale = false
        )
        assertEquals(CameraPermissionDecision.Request, decision)
    }

    @Test
    fun granted_takesPrecedenceOverRationaleFlag() {
        // Even if the system flags a rationale, we should launch when permission
        // is already granted.
        val decision = decideCameraPermissionFlow(
            isGranted = true,
            shouldShowRationale = true
        )
        assertEquals(CameraPermissionDecision.Launch, decision)
    }
}
