package com.adealink.weparty.oss

import com.adealink.frame.base.Rlt
import com.adealink.frame.oss.IOssCompressor

class OssCompressor : IOssCompressor {

    companion object {
        private const val TAG_COMPRESS = "tag_compress"

        const val IMAGE_MAX_WIDTH = 750
        const val IMAGE_MAX_HEIGHT = 1334
        const val IMAGE_MAX_SIZE_KB = 500
        const val IMAGE_MIN_QUALITY = 50


        const val VIDEO_RESOLUTION = 720 //720p
        const val VIDEO_BITRATE = 1_000_000 //1M
        const val VIDEO_MAX_SIZE_KB = 400 //需要执行压缩最小size
    }

    override suspend fun compressImage(path: String): Rlt<String> {
        return when (val result =
            com.adealink.weparty.commonui.mediapicker.imageselect.util.compressImage(
                path,
                IMAGE_MAX_WIDTH,
                IMAGE_MAX_HEIGHT,
                IMAGE_MAX_SIZE_KB,
                IMAGE_MIN_QUALITY
            )) {
            is Rlt.Success -> Rlt.Success(result.data.path)
            is Rlt.Failed -> result
        }
    }

    override suspend fun compressVideo(path: String): Rlt<String> {
        return when (val result =
            com.adealink.weparty.commonui.mediapicker.imageselect.util.compressVideo(
                path,
                VIDEO_RESOLUTION,
                VIDEO_BITRATE,
                VIDEO_MAX_SIZE_KB
            )) {
            is Rlt.Success -> Rlt.Success(result.data.path)
            is Rlt.Failed -> result
        }
    }

    override suspend fun compressFile(path: String): Rlt<String> {
        return Rlt.Success(path)
    }

}