package com.adealink.weparty.commonui.mediapicker.imageselect.util


object MediaMineType {
    const val MIME_TYPE_VIDEO = "video"
    const val MIME_TYPE_IMAGE = "image"
    const val MIME_TYPE_AUDIO = "audio"
    const val MIME_TYPE_OTHER = "other"

    private val videoExtensions = setOf("mp4", "avi", "3gpp", "3gp", "mov", "mkv", "flv")
    private val imageExtensions = setOf("png", "jpeg", "gif", "jpg", "webp", "bmp", "heic", "heif")
    private val audioExtensions = setOf("mp3", "wav", "flac", "ogg", "aac", "m4a", "wma")

    fun getMediaMimeType(filePath: String?): String {
        filePath ?: return MIME_TYPE_OTHER

        val extension = filePath
            .substringAfterLast('.', "")
            .takeIf { it.isNotEmpty() }
            ?.lowercase()
            ?: return MIME_TYPE_OTHER

        return when (extension) {
            in videoExtensions -> MIME_TYPE_VIDEO
            in imageExtensions -> MIME_TYPE_IMAGE
            in audioExtensions -> MIME_TYPE_AUDIO
            else -> MIME_TYPE_OTHER
        }
    }
}