use super::picture::Picture;
#[derive(Debug, Clone)]
pub struct Album<'a> {
pub title: Option<&'a str>,
pub artists: Option<Vec<&'a str>>,
pub covers: (Option<Picture>, Option<Picture>),
}
impl<'a> Default for Album<'a> {
fn default() -> Self {
Self {
title: None,
artists: None,
covers: (None, None),
}
}
}
impl<'a> Album<'a> {
pub fn new(
title: Option<&'a str>,
artists: Option<Vec<&'a str>>,
covers: (Option<Picture>, Option<Picture>),
) -> Self {
Self {
title,
artists,
covers,
}
}
pub fn with_title(title: &'a str) -> Self {
Self {
title: Some(title),
artists: None,
covers: (None, None),
}
}
pub fn set_artists(mut self, artists: Vec<&'a str>) {
self.artists = Some(artists);
}
pub fn append_artist(mut self, artist: &'a str) {
if let Some(mut artists) = self.artists {
artists.push(artist)
} else {
self.artists = Some(vec![artist])
}
}
pub fn remove_artists(mut self) {
self.artists = None
}
pub fn set_covers(mut self, covers: (Option<Picture>, Option<Picture>)) {
self.covers = covers
}
pub fn remove_covers(mut self) {
self.covers = (None, None)
}
pub fn artists_as_string(&self) -> Option<String> {
self.artists.as_ref().map(|artists| artists.join("/"))
}
}