package melody.offline.music.bean

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.ForeignKey
import androidx.room.ColumnInfo
import androidx.room.Index

@Entity(tableName = "playlists")
data class Playlist(
    @PrimaryKey(autoGenerate = true) val id: Int = 0,
    @ColumnInfo(name = "title") val title: String
)

@Entity(
    tableName = "playlist_items",
    foreignKeys = [
        ForeignKey(
            entity = Playlist::class,
            parentColumns = ["id"],
            childColumns = ["playlist_id"],
            onDelete = ForeignKey.CASCADE
        )
    ],
    indices = [Index(value = ["playlist_id"])]  // 添加索引
)
data class PlaylistItem(
    @PrimaryKey(autoGenerate = true) val id: Int = 0,
    @ColumnInfo(name = "playlist_id") val playlistId: Int? = null,
    @ColumnInfo(name = "videoId") var videoId: String,
    @ColumnInfo(name = "title") var title: String,
    @ColumnInfo(name = "name") var name: String,
    @ColumnInfo(name = "thumbnail") var thumbnail: String? = null,
    @ColumnInfo(name = "bytesDownloaded") var bytesDownloaded: Long? = null,
    @ColumnInfo(name = "size") var size: String? = null,
    @ColumnInfo(name = "isOffline") var isOffline: Boolean,
    @ColumnInfo(name = "isFavorite") var isFavorite: Boolean
)
