package ca.ksamad.encore.mpd.model

/**
 * Database/server statistics from a `stats` response. Durations are in seconds and the update
 * timestamp is Unix epoch seconds, both as MPD reports them.
 */
data class MpdStatistics(
    val artists: Int,
    val albums: Int,
    val songs: Int,
    val uptimeSeconds: Long,
    val playtimeSeconds: Long,
    val dbPlaytimeSeconds: Long,
    val dbUpdateEpochSeconds: Long,
) {
    companion object {
        fun from(values: Map<String, String>): MpdStatistics =
            MpdStatistics(
                artists = values["artists"]?.toIntOrNull() ?: 0,
                albums = values["albums"]?.toIntOrNull() ?: 0,
                songs = values["songs"]?.toIntOrNull() ?: 0,
                uptimeSeconds = values["uptime"]?.toLongOrNull() ?: 0,
                playtimeSeconds = values["playtime"]?.toLongOrNull() ?: 0,
                dbPlaytimeSeconds = values["db_playtime"]?.toLongOrNull() ?: 0,
                dbUpdateEpochSeconds = values["db_update"]?.toLongOrNull() ?: 0,
            )
    }
}
