package mg.dot.feufaro

import java.io.File

class DesktopPathValidator : PathValidator {
    private val systemTmpDir: String by lazy {
        try {
            File(System.getProperty("java.io.tmpdir")).absolutePath.lowercase()
        } catch (e: Exception) {
            "/tmp"
        }
    }

    override fun isRestrictedPath(path: String): Boolean {
        if (path.isEmpty()) return true

        val lowerPath = path.lowercase()

        val isInSystemTmp = lowerPath.contains(systemTmpDir)

        val isOtherRestricted = lowerPath.contains("/tmp/") ||
                lowerPath.contains("_tmp") ||
                lowerPath.contains("assets")

        return isInSystemTmp || isOtherRestricted
    }
}

actual fun getPathValidator(): PathValidator = DesktopPathValidator()