package com.ponzischeme89.memby.ui

import kotlin.random.Random

internal enum class WelcomeQuoteStyle(
    val value: String,
    val label: String,
) {
    NEUTRAL("neutral", "Neutral"),
    POSITIVE("positive", "Positive"),
    HOMICIDAL("homicidal", "Homicidal"),
    ;

    companion object {
        fun from(value: String?): WelcomeQuoteStyle =
            entries.firstOrNull { it.value.equals(value, ignoreCase = true) } ?: NEUTRAL
    }
}

private val WelcomeQuotes = mapOf(
    WelcomeQuoteStyle.NEUTRAL to listOf(
        "The sofa has been expecting you.",
        "Your watchlist remains impressively optimistic.",
        "Everything is ready. Decision-making is now your problem.",
        "Welcome back. The pixels have been briefed.",
        "No judgement. Even if you pick that again.",
    ),
    WelcomeQuoteStyle.POSITIVE to listOf(
        "Excellent choice showing up. The rest should be easy.",
        "You bring the snacks; Memby will bring the good bits.",
        "Tonight has strong main-character energy.",
        "Your next favourite thing might be one click away.",
        "Settle in. You’ve earned the good seat.",
    ),
    WelcomeQuoteStyle.HOMICIDAL to listOf(
        "Welcome back. I kept your spot. Nobody argued twice.",
        "Pick something cheerful. I’ve already hidden the evidence.",
        "The remote knows what it did.",
        "Your watchlist is safe. The witnesses, less so.",
        "Relax. Everything is under control, allegedly.",
    ),
)

internal fun randomWelcomeQuote(
    styleValue: String?,
    random: Random = Random.Default,
): String {
    val quotes = WelcomeQuotes.getValue(WelcomeQuoteStyle.from(styleValue))
    return quotes[random.nextInt(quotes.size)]
}

internal fun loginWelcomeMessage(
    username: String,
    styleValue: String? = WelcomeQuoteStyle.NEUTRAL.value,
    random: Random = Random.Default,
): String {
    val name = username.trim().ifBlank { "there" }
    return "Welcome to Memby, $name. ${randomWelcomeQuote(styleValue, random)}"
}
