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"

        private const val IMAGE_MAX_WIDTH = 1080
        private const val IMAGE_MAX_HEIGHT = 2340
        private const val IMAGE_MAX_SIZE_KB = 1000
        private const val IMAGE_MIN_QUALITY = 50

        private const val VIDEO_COMPRESS_MIN_SIZE_KB = 400 //需要执行压缩最小size
    }

    override suspend fun compressImage(path: String): Rlt<String> {
        return when (val result = com.adealink.weparty.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.imageselect.util.compressVideo(path, VIDEO_COMPRESS_MIN_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)
    }

}