use lunar_lib::database::{DatabaseEntry, DatabaseError, DbHandle};

use crate::{database::LibraryDb, library::album::Album};

impl Album {
    pub fn db_find_by_name(name: impl AsRef<str>) -> Result<Vec<Self>, DatabaseError>
    where
        Self: 'static,
    {
        let name = name.as_ref();

        let mut items = Vec::new();

        let db = DbHandle::<LibraryDb>::open()?;
        for album in Album::db_get_all(&db)? {
            if album.name == name {
                items.push(album);
            }
        }

        Ok(items)
    }
}
