export default (configuration) => {
    return `
    package ${configuration.packageName}.utils

    import android.graphics.Bitmap
    import android.media.MediaScannerConnection
    import android.util.Log
    import androidx.fragment.app.Fragment
    import java.io.ByteArrayOutputStream
    import java.io.File
    import java.io.FileOutputStream
    import java.io.IOException
    import java.util.Calendar
    import android.content.Context
    import android.net.Uri
    import android.os.Build
    import android.os.Environment
    import android.provider.DocumentsContract
    
   
    object FileUtils {
    
        fun Fragment.saveImage(myBitmap: Bitmap): String {
            val bytes = ByteArrayOutputStream()
            myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
            val localStorage: File? = activity?.getExternalFilesDir(null)
            val storagePath = localStorage?.absolutePath
            val rootPath = "$storagePath/luv"
            val root = File(rootPath)
            if (!root.mkdirs()) {
                Log.i("Test", "This path is already exist: " + root.absolutePath)
            }
            try {
                val f = File("$root/\${Calendar.getInstance().timeInMillis}.jpeg")
                f.createNewFile()
                val fo = FileOutputStream(f)
                fo.write(bytes.toByteArray())
                MediaScannerConnection.scanFile(
                    context,
                    arrayOf(f.path),
                    arrayOf("image/jpeg", "image/jpg"),
                    null
                )
                fo.close()
                return f.absolutePath
            } catch (e1: IOException) {
                e1.printStackTrace()
            }
            return ""
        }

        fun Fragment.getPathFromUri(context: Context, uri: Uri?): String {
            var filePath = ""

            // ExternalStorageProvider
            val docId = DocumentsContract.getDocumentId(uri)
            val split = docId.split(':').toTypedArray()
            val type = split[0]

            if ("primary".equals(type, ignoreCase = true)) {
                return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
            } else {
                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
                    // getExternalMediaDirs() added in API 21
                    val external = context.externalMediaDirs
                    if (external.size > 1) {
                        filePath = external[1].absolutePath
                        filePath = filePath.substring(0, filePath.indexOf("Android")) + split[1]
                    }
                } else {
                    filePath = "/storage/$type/\${split[1]}"
                }
                return filePath
            }
        }
    }
    `
}