package com.base.easyfilemanager.bean

import java.io.File

data class FileBean(
    var name: String = "",
    var path: String,
    val size: Long,
    val isDir: Boolean = false,
    var type: String = "",
    val time: Long = 0L,
    var isSelect: Boolean = false
) {
    fun isEmptyFile() = !isDir && (File(path).length() == 0L)

    fun isImage() = !isDir && type in listOf("png", "jpg", "gif")

    fun isVideo() = !isDir && type in listOf("mp4")

    fun isAudio() = !isDir && type in listOf("mp3")

    fun isZip() = !isDir && type in listOf("zip", "tar", "7z")

    fun isApk() = !isDir && type in listOf("apk")

    fun isDoc() = !isDir && type in listOf("pdf", "doc", "docx", "xls", "ppt", "txt")

    fun isOther() = !isImage() && !isVideo() && !isAudio() && !isZip() && !isApk()

    override fun toString(): String {
        return "FileBean(name='$name', path='$path', size=$size, isDir=$isDir, type='$type', time=$time, isSelect=$isSelect)"
    }
    companion object {
        fun isDir(file: File): Boolean {
            return file.isDirectory
        }


        fun isImage(file: File): Boolean {
            return file.name.contains(".jpg") or
                    file.name.contains(".png") or
                    file.name.contains(".gif")
        }

        fun isVideo(file: File): Boolean {
            return file.name.contains(".mp4") or
                    file.name.contains(".avi") or
                    file.name.contains(".flv") or
                    file.name.contains(".rmvb") or
                    file.name.contains(".mkv")
        }

        fun isAudio(file: File): Boolean {
            return file.name.contains(".mp3") or
                    file.name.contains(".aac") or
                    file.name.contains(".ogg") or
                    file.name.contains(".m4a") or
                    file.name.contains(".aac")
        }

        fun isLargeFile(file: File): Boolean {
            return file.length() >= 10 * 1024 * 1024
        }


        fun isZip(file: File): Boolean {
            return file.name.contains(".zip")
        }

        fun isApk(file: File): Boolean {
            return file.name.contains(".apk")
        }

        fun isDocument(file: File): Boolean {
            return file.name.contains(".doc") or
                    file.name.contains(".docx") or
                    file.name.contains(".ppt") or
                    file.name.contains(".pptx") or
                    file.name.contains(".xls") or
                    file.name.contains(".xlsx") or
                    file.name.contains(".txt") or
                    file.name.contains(".pdf")
        }
    }
}