package com.zxhy.hfilemanagermaster.data

import android.content.Context
import android.net.Uri
import android.text.format.Formatter
import java.io.File
import java.text.SimpleDateFormat
import java.util.Locale

const val MediaDataC_TYPE_IMAGE = 101
const val MediaDataC_TYPE_VIDEO = 102

data class MediaDataC(
    val name: String = "File name",
    val size: String = "20MB",
    val time: String = "January 5, 2024",
    val type: Int = MediaDataC_TYPE_IMAGE,
    val uri: Uri = Uri.EMPTY,
    val path: String = "",
    val md5: String = "",
    var select: Boolean = false,
    var index: Int = 0
) {
}

fun File.file2MediaDataC(context: Context, md5: String = ""): MediaDataC {
    return try {
        val sizeS = Formatter.formatFileSize(context, length())
        val timeE = SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH).format(lastModified())
        MediaDataC(
            name = name,
            size = sizeS,
            time = timeE,
            path = absolutePath,
            md5 = md5
        )
    } catch (e: Exception) {
        MediaDataC()
    }
}