package com.dumpster.cleaner.utils

import android.webkit.MimeTypeMap

object MineTypeUtils {

    val TYPE_VIDEO = 0
    val TYPE_IMAGE = 1
    val TYPE_AUDIO = 2

    val mineTypes by lazy {
        listOf(
            "image/",
            "video/",
            "audio/",
            "text/",
            MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf") ?: "",
            MimeTypeMap.getSingleton().getMimeTypeFromExtension("doc") ?: "",
            MimeTypeMap.getSingleton().getMimeTypeFromExtension("docx") ?: "",
            MimeTypeMap.getSingleton().getMimeTypeFromExtension("xls") ?: "",
            MimeTypeMap.getSingleton().getMimeTypeFromExtension("xlsx") ?: "",
            MimeTypeMap.getSingleton().getMimeTypeFromExtension("ppt") ?: "",
            MimeTypeMap.getSingleton().getMimeTypeFromExtension("apk") ?: "",
        )
    }

    val images = listOf(".jpeg", ".jpg", ".png", ".gif", ".webp", ".ico", ".raw") // 图像
    val videos = listOf(".mp4", ".avi", ".mov", ".wmv", ".flv") // 视频
    val audios = listOf(".mp3", ".wav", ".m4a", ".ncm") // 音频
    val apks = listOf(".apk", ".aab")
    val temps = listOf(".temp")
    val logs = listOf(".log")

    fun isImage(mineType: String): Boolean {
        return mineType.startsWith(mineTypes[0])
    }

    fun isVideo(mineType: String): Boolean {
        return mineType.startsWith(mineTypes[1])
    }

    fun isAudio(mineType: String): Boolean {
        return mineType.startsWith(mineTypes[2])
    }

    fun isDoc(mineType: String): Boolean {
        return mineType.startsWith(mineTypes[3])
                || mineType.startsWith(mineTypes[4])
                || mineType.startsWith(mineTypes[5])
                || mineType.startsWith(mineTypes[6])
                || mineType.startsWith(mineTypes[7])
                || mineType.startsWith(mineTypes[8])
                || mineType.startsWith(mineTypes[9])
    }

    fun isApk(mineType: String): Boolean {
        return mineType.startsWith(mineTypes[10])
    }
}