use crate::app::SongInfo;
use crate::app::song::Album;
#[derive(Debug, Clone)]
pub struct Artist {
pub name: String,
pub albums: Vec<Album>,
}
#[derive(Debug, Clone)]
pub(crate) enum ArtistData {
NotLoaded,
Loading,
Loaded(Vec<Album>),
}
#[derive(Debug, Clone)]
pub struct LazyArtist {
pub name: String,
pub albums: ArtistData,
}
impl LazyArtist {
pub fn new(name: String) -> Self {
let name = SongInfo::sanitize_string(&name);
Self {
name,
albums: ArtistData::NotLoaded,
}
}
pub fn is_loaded(&self) -> bool {
matches!(self.albums, ArtistData::Loaded(_))
}
pub fn is_loading(&self) -> bool {
matches!(self.albums, ArtistData::Loading)
}
pub fn to_artist(&self) -> Artist {
let albums = match &self.albums {
ArtistData::Loaded(albums) => albums.clone(),
_ => Vec::new(),
};
Artist {
name: self.name.clone(),
albums,
}
}
}