1use serde::Serialize;
2use zbus::zvariant::{ObjectPath, Type, Value};
3
4use crate::{PlaylistId, Uri};
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Type)]
8pub struct Playlist {
9 pub id: PlaylistId,
13 pub name: String,
15 pub icon: Uri,
17}
18
19impl<'a> From<Playlist> for Value<'a> {
20 fn from(p: Playlist) -> Self {
21 Value::from((p.id, p.name, p.icon))
22 }
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Type)]
34#[doc(alias = "Maybe_Playlist")]
35pub(crate) struct MaybePlaylist {
36 valid: bool,
38 playlist: Playlist,
45}
46
47impl From<Option<Playlist>> for MaybePlaylist {
48 fn from(playlist: Option<Playlist>) -> Self {
49 match playlist {
50 Some(playlist) => Self {
51 valid: true,
52 playlist,
53 },
54 None => Self {
55 valid: false,
56 playlist: Playlist {
57 id: ObjectPath::from_static_str_unchecked("/").into(),
58 name: String::new(),
59 icon: Uri::new(),
60 },
61 },
62 }
63 }
64}
65
66impl<'a> From<MaybePlaylist> for Value<'a> {
67 fn from(mp: MaybePlaylist) -> Self {
68 Value::from((mp.valid, mp.playlist))
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn valid_signatures() {
78 assert_eq!(Playlist::signature(), "(oss)");
79 assert_eq!(MaybePlaylist::signature(), "(b(oss))");
80 }
81}