use std::str::FromStr;

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

use crate::{
    database::LibraryDb,
    library::collection::{Collection, CollectionId},
};

impl Collection {
    pub fn db_find_by_name(name: impl AsRef<str>) -> Result<Option<Self>, DatabaseError>
    where
        Self: 'static,
    {
        let db = DbHandle::<LibraryDb>::open()?;
        Ok(CollectionId::from_str(name.as_ref()).unwrap().db_get(&db)?)
    }
}
