package com.pixelized.desktop.lwa.ui.composable.image

class ImagerModelConverter {

    val googleDriveUrlRegex = Regex("""drive\.google\.com/file/d/([^/]*)""")
    val workingGoogleDriveUri = "https://drive.google.com/uc?export=view&id="

    fun convert(
        model: Any?,
    ): Any? {
        return when (model) {
            is String -> unwrap(model = model)
            else -> model
        }
    }

    fun unwrap(
        model: String,
    ): String {
        return googleDriveUrlRegex.find(model)?.let {
            val id = it.groupValues.getOrNull(1)
            "$workingGoogleDriveUri$id"
        } ?: model
    }
}