use heromodels_core::BaseModelData; use heromodels_derive::model; use rhai::{CustomType, TypeBuilder}; use serde::{Deserialize, Serialize}; /// Represents a collection of library items. #[model] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)] pub struct Collection { /// Base model data pub base_data: BaseModelData, /// Title of the collection #[index] pub title: String, /// Optional description of the collection pub description: Option, /// List of image item IDs belonging to this collection pub images: Vec, /// List of PDF item IDs belonging to this collection pub pdfs: Vec, /// List of Markdown item IDs belonging to this collection pub markdowns: Vec, /// List of Book item IDs belonging to this collection pub books: Vec, /// List of Slides item IDs belonging to this collection pub slides: Vec, } impl Default for Collection { fn default() -> Self { Self { base_data: BaseModelData::new(), title: String::new(), description: None, images: Vec::new(), pdfs: Vec::new(), markdowns: Vec::new(), books: Vec::new(), slides: Vec::new(), } } } impl Collection { /// Creates a new `Collection` with default values. pub fn new() -> Self { Self::default() } /// Returns the ID of the collection. pub fn id(&self) -> u32 { self.base_data.id } /// Sets the title of the collection. pub fn title(mut self, title: impl Into) -> Self { self.title = title.into(); self } /// Sets the description of the collection. pub fn description(mut self, description: impl Into) -> Self { self.description = Some(description.into()); self } /// Adds an image ID to the collection. pub fn add_image(mut self, image_id: u32) -> Self { self.images.push(image_id); self } /// Adds a PDF ID to the collection. pub fn add_pdf(mut self, pdf_id: u32) -> Self { self.pdfs.push(pdf_id); self } /// Adds a markdown ID to the collection. pub fn add_markdown(mut self, markdown_id: u32) -> Self { self.markdowns.push(markdown_id); self } /// Adds a book ID to the collection. pub fn add_book(mut self, book_id: u32) -> Self { self.books.push(book_id); self } /// Adds a slides ID to the collection. pub fn add_slides(mut self, slides_id: u32) -> Self { self.slides.push(slides_id); self } }