package com.horrortv.app.util

object PosterSize {
    const val CARD = 600
    const val DETAIL = 800
    const val BACKGROUND = 2160
    const val THUMBNAIL = 300
}

object PosterUtils {
    
    fun optimizePosterUrl(url: String?, targetSize: Int): String? {
        if (url.isNullOrEmpty() || url == "N/A") return null
        
        val sizePattern = Regex("\\._V1_(SX|UX|SY|UY)\\d+")
        return url.replace(sizePattern, "._V1_SX${targetSize.coerceAtLeast(300)}")
    }
    
    fun toHighQuality(url: String?): String {
        return optimizePosterUrl(url, PosterSize.DETAIL) ?: ""
    }
}

fun String?.toPosterUrl4K(): String {
    return PosterUtils.optimizePosterUrl(this, PosterSize.BACKGROUND) ?: ""
}

fun String.isValidImdbId(): Boolean {
    return Constants.IMDB_ID_PATTERN.matches(this)
}