package com.rosetta.messenger.ui.settings

import androidx.annotation.DrawableRes
import com.rosetta.messenger.R

data class ThemeWallpaper(
    val id: String,
    val name: String,
    val preferredTheme: WallpaperTheme,
    @DrawableRes val drawableRes: Int
)

enum class WallpaperTheme {
    DARK,
    LIGHT
}

object ThemeWallpapers {
    // Desktop parity: keep the same order/mapping as desktop WALLPAPERS.
    val all: List<ThemeWallpaper> =
        listOf(
            ThemeWallpaper(
                id = "back_3",
                name = "Wallpaper 1",
                preferredTheme = WallpaperTheme.DARK,
                drawableRes = R.drawable.wallpaper_back_3
            ),
            ThemeWallpaper(
                id = "back_4",
                name = "Wallpaper 2",
                preferredTheme = WallpaperTheme.LIGHT,
                drawableRes = R.drawable.wallpaper_back_4
            ),
            ThemeWallpaper(
                id = "back_5",
                name = "Wallpaper 3",
                preferredTheme = WallpaperTheme.DARK,
                drawableRes = R.drawable.wallpaper_back_5
            ),
            ThemeWallpaper(
                id = "back_6",
                name = "Wallpaper 4",
                preferredTheme = WallpaperTheme.LIGHT,
                drawableRes = R.drawable.wallpaper_back_6
            ),
            ThemeWallpaper(
                id = "back_7",
                name = "Wallpaper 5",
                preferredTheme = WallpaperTheme.LIGHT,
                drawableRes = R.drawable.wallpaper_back_7
            ),
            ThemeWallpaper(
                id = "back_8",
                name = "Wallpaper 6",
                preferredTheme = WallpaperTheme.LIGHT,
                drawableRes = R.drawable.wallpaper_back_8
            ),
            ThemeWallpaper(
                id = "back_9",
                name = "Wallpaper 7",
                preferredTheme = WallpaperTheme.LIGHT,
                drawableRes = R.drawable.wallpaper_back_9
            ),
            ThemeWallpaper(
                id = "back_10",
                name = "Wallpaper 8",
                preferredTheme = WallpaperTheme.LIGHT,
                drawableRes = R.drawable.wallpaper_back_10
            ),
            ThemeWallpaper(
                id = "back_11",
                name = "Wallpaper 9",
                preferredTheme = WallpaperTheme.DARK,
                drawableRes = R.drawable.wallpaper_back_11
            ),
            ThemeWallpaper(
                id = "back_1",
                name = "Wallpaper 10",
                preferredTheme = WallpaperTheme.LIGHT,
                drawableRes = R.drawable.wallpaper_back_1
            ),
            ThemeWallpaper(
                id = "back_2",
                name = "Wallpaper 11",
                preferredTheme = WallpaperTheme.DARK,
                drawableRes = R.drawable.wallpaper_back_2
            )
        )

    fun findById(id: String): ThemeWallpaper? = all.firstOrNull { it.id == id }

    fun forTheme(isDarkTheme: Boolean): List<ThemeWallpaper> {
        val targetTheme = if (isDarkTheme) WallpaperTheme.DARK else WallpaperTheme.LIGHT
        return all.filter { it.preferredTheme == targetTheme }
    }

    @DrawableRes
    fun drawableResOrNull(id: String): Int? = findById(id)?.drawableRes
}
