package com.zxhy.fastfilemanagerpro.kokolistfile

import android.content.Context
import com.zxhy.fastfilemanagerpro.CommonViewModel
import com.zxhy.fastfilemanagerpro.kokodata.KoFileDatako
import java.io.File

class KoListFilekoViewModel : CommonViewModel() {


    fun isEmptyFilter(file: File): Boolean {
        return file.length() == 0L
    }

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

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

    fun isLogFilter(file: File): Boolean {
        return file.name.contains("log") or file.name.contains("Log")
    }

    fun isZipFilter(file: File): Boolean {
        return file.name.contains(".zip") or file.name.contains(".7z")
    }

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

    fun isDocumentsFilter(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")
    }

    fun loadEmptyFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isEmptyFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }

    fun loadLargeFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isLargeFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }

    fun loadAudioFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isAudioFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }

    fun loadLogFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isLogFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }

    fun loadZipFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isZipFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }

    fun loadApkFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isApkFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }


    fun loadDocumentsFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isDocumentsFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }

}