package com.fabledsword.minstrel.models

/**
 * Lightweight reference to one album. Mirrors
 * `flutter_client/lib/models/album.dart`'s `AlbumRef`.
 *
 * `coverUrl` and `durationSec` match the server contract (not
 * `cover_art_url` / `duration_ms`). `year` is omitempty server-side so
 * stays nullable. `coverUrl` is non-null but may be empty — UI branches
 * on isEmpty.
 */
data class AlbumRef(
    val id: String,
    val title: String,
    val artistId: String,
    val sortTitle: String = "",
    val artistName: String = "",
    val year: Int? = null,
    val trackCount: Int = 0,
    val durationSec: Int = 0,
    val coverUrl: String = "",
) {
    /**
     * Cover URL the UI should render. Returns the server-provided
     * `coverUrl` when populated (regular API responses always carry it),
     * otherwise derives `/api/albums/{id}/cover` via the placeholder
     * host that `BaseUrlInterceptor` rewrites to the live server URL.
     *
     * The fallback path matters because the cached_albums entity →
     * AlbumRef mapper drops coverUrl — without this property,
     * AlbumCards rendered from cache (Library Albums tab, ArtistDetail
     * grid, Home rows on cold-start) would show no artwork at all.
     */
    val displayCoverUrl: String
        get() = coverUrl.ifEmpty { albumCoverPath(id) }
}
