use std::fs::File; use std::io::{Error, ErrorKind}; use uuid::Uuid; use lumiere_domain::video::model::library_item::{LibraryItem, LibraryItemType, LibraryRawItem}; pub struct TokioVideoFile { pub file: File } impl TokioVideoFile { pub fn new(file_path: &String) -> Self { Self { file: File::open(file_path).expect(format!("Failed to open file {file_path}").as_str()) } } } pub struct LibraryItemEntity { pub id: Uuid, pub name: String, pub r#type: i8, pub parent_folder_id: Option } impl LibraryItemEntity { pub fn from_library_item(library_item: &LibraryItem) -> Self { Self { id: library_item.id.clone(), name: library_item.name.clone(), r#type: Self::map_type_to_i8(library_item.r#type)?, parent_folder_id: None } } fn map_type_to_i8(item_type: LibraryItemType) -> Result { match item_type { LibraryItemType::VIDEO => Ok(0), LibraryItemType::FOLDER => Ok(1) } } fn map_type_from_i8(item_type_number: i8) -> Result { match item_type_number { 0 => Ok(LibraryItemType::VIDEO), 1 => Ok(LibraryItemType::FOLDER), unknown_value => Err(Error::new(ErrorKind::InvalidData, format!("Unknown library item type value from database: {unknown_value}"))) } } pub(crate) fn to_library_raw_item(self) -> Result { let library_item = LibraryRawItem { id: Some(self.id.clone()), name: self.name.clone(), r#type: Self::map_type_from_i8(self.r#type)? }; Ok(library_item) } }