package melody.offline.music.database

import androidx.room.*
import melody.offline.music.bean.Playlist
import melody.offline.music.bean.PlaylistItem

@Dao
interface PlaylistDao {
    @Insert
    suspend fun insertPlaylist(playlist: Playlist): Long

    @Insert
    suspend fun insertPlaylistItem(playlistItem: PlaylistItem): Long

    @Query("SELECT * FROM playlists WHERE id = :id")
    suspend fun getPlaylistById(id: Int): Playlist?

    @Query("SELECT * FROM playlists WHERE title = :title")
    suspend fun getPlaylistByTitle(title: String): Playlist?

    @Query("SELECT * FROM playlist_items WHERE id = :id")
    suspend fun getPlaylistItemById(id: Int): PlaylistItem?

    @Query("SELECT * FROM playlists")
    fun getAllPlaylists(): List<Playlist>

    @Query("SELECT * FROM playlist_items WHERE playlist_id = :playlistId")
    fun getPlaylistItems(playlistId: Int): List<PlaylistItem>

    @Update
    suspend fun updatePlaylist(playlist: Playlist)

    @Update
    suspend fun updatePlaylistItem(playlistItem: PlaylistItem)

    @Update
    suspend fun updatePlaylistItems(playlistItems: List<PlaylistItem>)

    @Delete
    suspend fun deletePlaylist(playlist: Playlist)

    @Delete
    suspend fun deletePlaylistItem(playlistItem: PlaylistItem)
}