package com.ponzischeme89.memby.data.model

fun MediaRating.wordmark(): String = when (source.lowercase()) {
    "tomatoes" -> "RT"
    "audience" -> "RT Audience"
    "metacritic" -> "Metacritic"
    "letterboxd" -> "Letterboxd"
    "mal" -> "MAL"
    "anilist" -> "AniList"
    "anidb" -> "AniDB"
    "kitsu" -> "Kitsu"
    "imdb" -> "IMDb"
    "tmdb" -> "TMDb"
    "trakt" -> "Trakt"
    else -> name.trim()
}

fun MediaRating.formattedScore(): String = when (source.lowercase()) {
    "tomatoes", "audience", "trakt", "anilist", "kitsu" -> "$score%"
    else -> score
}

fun List<MediaRating>.displayable(): List<MediaRating> = filter { rating ->
    rating.wordmark().isNotBlank() && rating.score.toDoubleOrNull()?.let { it > 0.0 } == true
}.distinctBy { it.source.lowercase() }

fun ratingDisplayLimit(widthDp: Int): Int = when {
    widthDp < 120 -> 1
    widthDp < 220 -> 2
    widthDp < 360 -> 3
    else -> Int.MAX_VALUE
}

fun ratingsStripVisible(enabled: Boolean, ratings: List<MediaRating>): Boolean =
    enabled && ratings.displayable().isNotEmpty()
