use yog_registry::ItemDef;
#[derive(Debug, Clone)]
pub struct BookCategory {
pub id: String,
pub name: String,
pub description: Option<String>,
}
#[derive(Debug, Clone)]
pub enum BookPage {
Text { text: String },
Item { item: ItemDef },
}
#[derive(Debug, Clone)]
pub struct BookEntry {
pub id: String,
pub name: String,
pub category: String,
pub pages: Vec<BookPage>,
}
#[derive(Debug, Clone, Default)]
pub struct Book {
pub id: String,
pub name: String,
pub author: Option<String>,
pub categories: Vec<BookCategory>,
pub entries: Vec<BookEntry>,
}
impl Book {
pub fn new(id: impl Into<String>, name: impl Into<String>) -> Self {
Self {
id: id.into(),
name: name.into(),
author: None,
categories: Vec::new(),
entries: Vec::new(),
}
}
pub fn author(mut self, author: impl Into<String>) -> Self {
self.author = Some(author.into());
self
}
pub fn add_category(mut self, category: BookCategory) -> Self {
self.categories.push(category);
self
}
pub fn add_entry(mut self, entry: BookEntry) -> Self {
self.entries.push(entry);
self
}
}
#[derive(Debug, Default)]
pub struct BookRegistry {
books: std::collections::HashMap<String, Book>,
}
impl BookRegistry {
pub fn register(&mut self, book: Book) {
self.books.insert(book.id.clone(), book);
}
pub fn get(&self, id: &str) -> Option<&Book> {
self.books.get(id)
}
}