package com.example.livingai.domain.camera

import android.graphics.Bitmap
import com.example.livingai.domain.model.camera.CameraOrientation
import com.example.livingai.domain.model.camera.CaptureData
import com.example.livingai.domain.model.camera.DetectionResult
import com.example.livingai.domain.model.camera.Instruction
import com.example.livingai.domain.model.camera.ObjectMetrics
import com.example.livingai.domain.model.camera.ReferenceObject

interface CameraPipelineStep {
    /**
     * Analyzes the current frame (or sensor data) and returns an instruction.
     */
    suspend fun analyze(input: PipelineInput): Instruction
}

data class PipelineInput(
    val image: Bitmap?,
    val deviceOrientation: Int, // degrees
    val deviceRoll: Float,
    val devicePitch: Float,
    val deviceAzimuth: Float,
    val requiredOrientation: CameraOrientation,
    val screenWidthPx: Float,
    val screenHeightPx: Float,
    val targetAnimal: String, // e.g., "Dog", "Cat"
    val orientation: String, // "front", "back", "side", etc.
    val previousDetectionResult: DetectionResult? = null // To pass detection result to subsequent steps
)

interface OrientationChecker : CameraPipelineStep
interface TiltChecker : CameraPipelineStep
interface ObjectDetector : CameraPipelineStep
interface PoseAnalyzer : CameraPipelineStep

interface CaptureHandler {
    suspend fun capture(input: PipelineInput, detectionResult: DetectionResult): CaptureData
}

interface MeasurementCalculator {
    /**
     * Calculates the real world dimensions of the animal based on a known reference object dimension.
     * @param targetHeight The real height of the reference object provided by the user.
     * @param referenceObject The reference object selected by the user.
     * @param currentMetrics The current relative metrics of the animal.
     * @return The calculated real-world metrics for the animal.
     */
    fun calculateRealMetrics(
        targetHeight: Float, 
        referenceObject: ReferenceObject, 
        currentMetrics: ObjectMetrics
    ): RealWorldMetrics
}

data class RealWorldMetrics(
    val height: Float,
    val width: Float,
    val distance: Float,
    val unit: String = "cm"
)
