package com.adealink.weparty.imageselect.clip

import android.content.Context
import android.content.Intent
import android.os.Parcelable
import androidx.activity.result.contract.ActivityResultContract
import com.adealink.frame.base.fastLazy
import com.adealink.frame.util.DisplayUtil
import kotlinx.parcelize.Parcelize

data class ClipImageRequest(
    val inputPath: String,
    val outputPath: String,
    val clipParamData: ClipParamData?,
)

@Parcelize
data class ClipParamData(
    val clipViewHorizontalPaddingDp: Int = 0,
    val clipWidthHeightRatio: Double = 1.0,
    val useHighQuality: Boolean,
) : Parcelable

@Parcelize
data class MesTipData(
    val isShow: Boolean = false,
    val showMes: MesType? = null,  // false 房间封面 / true 头像
) : Parcelable

enum class MesType(val type: Int){
    Avatar(1),
    RoomCover(2),
}

val avatarClipParam by fastLazy { ClipParamData(DisplayUtil.dp2px(10f), 1.0, true) }

data class ClipImageResult(
    val resultCode: Int,
    val inputPath: String,
    val outputPath: String,
)

class ClipImageContract : ActivityResultContract<ClipImageRequest, ClipImageResult>() {

    private var inputPath: String = ""
    private var outputPath: String = ""

    override fun createIntent(context: Context, input: ClipImageRequest): Intent {
        inputPath = input.inputPath
        outputPath = input.outputPath
        return Intent(context, ClipImageActivity::class.java).apply {
            putExtra(
                ClipImageView.HORIZONTAL_PADDING,
                input.clipParamData?.clipViewHorizontalPaddingDp
            )
            putExtra(ClipImageView.WIDTH_HEIGHT_RATIO, input.clipParamData?.clipWidthHeightRatio)
            putExtra(ClipImageActivity.EXTRA_IMAGE_PATH, input.inputPath)
            putExtra(ClipImageActivity.EXTRA_OUTPUT_IMAGE_PATH, input.outputPath)
            putExtra(ClipImageActivity.EXTRA_HIGH_QUALITY, input.clipParamData?.useHighQuality)
        }
    }

    override fun parseResult(resultCode: Int, intent: Intent?): ClipImageResult {
        return ClipImageResult(resultCode, inputPath, outputPath)
    }
}