package de.tsschulz.tt_tagebuch.shared.api.models

private val imageIdInPath = Regex("/image/(\\d+)")

fun PredefinedActivitySummary?.hasDisplayableImage(): Boolean {
    if (this == null) return false
    val link = imageLink?.trim().orEmpty()
    if (link.isEmpty()) return false
    return imageIdInPath.containsMatchIn(link)
}

/** Relativer API-Pfad (beginnt mit `/`) oder `null`. */
fun PredefinedActivitySummary?.imageRelativePath(): String? {
    if (!hasDisplayableImage()) return null
    val link = this!!.imageLink!!.trim()
    return if (link.startsWith("/")) link else "/$link"
}

fun DiaryDateActivityItem.mainActivityImagePath(): String? =
    predefinedActivity.imageRelativePath()

fun GroupActivitySummary.nestedActivityImagePath(): String? =
    groupPredefinedActivity.imageRelativePath()
