package com.fabledsword.minstrel.models

/**
 * Kind of Lidarr request being created. Wire form is the lowercase
 * enum name; the helper [wire] keeps that mapping in one place.
 */
enum class LidarrRequestKind {
    ARTIST, ALBUM, TRACK;

    val wire: String get() = name.lowercase()
}

/**
 * Lidarr search hit. Mirrors `flutter_client/lib/models/lidarr.dart`'s
 * `LidarrSearchResult` — `mbid` is the result's own MBID; `artistMbid`
 * and `albumMbid` are filled when the row is an album/track and the
 * UI needs the parent IDs to build the request.
 *
 * `inLibrary` and `requested` together cover the "already-handled"
 * cases — UI greys the row + swaps the Request button for a pill.
 */
data class LidarrSearchResultRef(
    val mbid: String,
    val name: String,
    val secondaryText: String = "",
    val imageUrl: String = "",
    val artistMbid: String = "",
    val albumMbid: String = "",
    val inLibrary: Boolean = false,
    val requested: Boolean = false,
)

/**
 * Per-seed attribution string for a suggestion — "you liked X" /
 * "you played Y". `isLiked = true` discriminates the verb.
 */
data class SeedContributionRef(
    val name: String,
    val isLiked: Boolean,
)

/**
 * Out-of-library artist suggestion from `GET /api/discover/suggestions`.
 * `attributionText` mirrors Flutter's SuggestionFeed.attributionText
 * (Oxford-comma, max 3 seeds) so the subtitle reads naturally.
 */
data class ArtistSuggestionRef(
    val mbid: String,
    val name: String,
    val imageUrl: String = "",
    val attribution: List<SeedContributionRef> = emptyList(),
) {
    val attributionText: String
        get() {
            if (attribution.isEmpty()) return ""
            val phrases = attribution
                .take(MAX_ATTRIBUTION_PHRASES)
                .map { "${if (it.isLiked) "liked" else "played"} ${it.name}" }
            return when (phrases.size) {
                1 -> "Because you ${phrases[0]}."
                2 -> "Because you ${phrases[0]} and ${phrases[1]}."
                else -> "Because you ${phrases[0]}, ${phrases[1]}, and ${phrases[2]}."
            }
        }

    companion object {
        private const val MAX_ATTRIBUTION_PHRASES = 3
    }
}
