package com.base.filerecoveryrecyclebin.utils

import android.provider.MediaStore.Audio.Radio
import java.io.File
import kotlin.random.Random

object SimilarHelper {


    fun calculate(list: ArrayList<File>) {

        val result = HashMap<String, ArrayList<File>>()
        val eachArrayList = arrayListOf<File>().apply {
            addAll(list)
        }
        val comparedFile = arrayListOf<File>()

        val iterator = list.iterator()
        val compareIterator = eachArrayList.iterator()

        while (iterator.hasNext()) {
            val item = iterator.next()

            if (!comparedFile.contains(item)) {
                while (compareIterator.hasNext()) {
                    val compareItem = compareIterator.next()

                    if (item.absoluteFile != compareItem.absoluteFile) {

                        val percent = similarPercent(item, compareItem)
                        if (percent > 80) {
                            if (result[item.absolutePath] == null) {
                                result[item.absolutePath] = arrayListOf()
                            }
                            result[item.absolutePath]?.add(item)
                            result[item.absolutePath]?.add(compareItem)
                            comparedFile.add(compareItem)
                            compareIterator.remove()
                        }

                    }
                }
            }

        }

    }

    private fun similarPercent(srcFile: File, compareFile: File): Int {
        return Random.nextInt(60, 100)

    }

}