Newer
Older
bremer / src / main / kotlin / model / api / Api.kt
/*
 * Copyright (c) 2023. yo-saito. All Rights Reserved.
 */

package net.piedpiper.bremer.model.api

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.validation.constraints.NotBlank
import net.piedpiper.bremer.entity.AudioEntity
import net.piedpiper.bremer.entity.PlaylistEntity

data class AudioListResponse(
    private val entities: List<AudioEntity>
) {
    val audio: List<Audio> =
        entities.map { Audio(it) }

    data class Audio(
        private val entity: AudioEntity
    ) {
        val name: String = entity.name
        val slug: String = entity.slug
        val artist: String? = entity?.album?.artist?.name
        val album: String? = entity?.album?.name
        var sequence: Int? = if (entity?.sequence == 0) { entity?.sequence } else { null }
        var aliasNames: List<String>? = entity?.aliasNames?.map { it.name }
    }
}

data class PlaylistListRequest(
    @field:JsonProperty("playlist_slugs")
    val playlistSlugs: List<String>
)

data class PlaylistListResponse(
    private val entities: List<PlaylistEntity>
) {
    val playlist: List<Playlist> = entities.map { Playlist(it.name, it.sequence, it.slug) }

    data class Playlist(
        val name: String,
        var sequence: Int,
        val slug: String
    )
}

data class PlaylistRequest(
    @field:NotBlank
    val name: String = "",

    @field:JsonProperty("audio_slugs")
    val audioSlugs: List<String> = mutableListOf()
)

class PlaylistAudioResponse(
    private val playlistEntity: PlaylistEntity,
    private val audioEntityList: List<AudioEntity>
) {
    val name: String = playlistEntity.name
    val slug: String = playlistEntity.slug

    @field:JsonProperty("audio_list")
    val audioList: List<Audio> = audioEntityList.map { Audio(it) }

    @JsonInclude(JsonInclude.Include.NON_NULL)
    class Audio(private val entity: AudioEntity) {
        val name: String = entity.name
        val aliasName : List<String> = entity.aliasNames?.map { it.name } ?: emptyList()
        val slug: String = entity.slug
        val artist: String? = entity.album?.artist?.name
        val album: String? = entity.album?.name
    }
}