use std::{error::Error, fmt::Display, path::PathBuf}; use color_eyre::eyre::{eyre, Result}; use tracing::debug; use crate::{ images::Image, kinds::ServiceItemKind, presentations::Presentation, songs::Song, videos::Video, }; #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum TextAlignment { TopLeft, TopCenter, TopRight, MiddleLeft, #[default] MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight, } #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct Background { path: PathBuf, kind: BackgroundKind, } impl TryFrom for Background { type Error = ParseError; fn try_from(value: String) -> Result { let extension = value.rsplit_once('.').unwrap_or_default(); match extension.0 { "jpg" | "png" | "webp" => Ok(Self { path: PathBuf::from(value), kind: BackgroundKind::Image, }), "mp4" | "mkv" | "webm" => Ok(Self { path: PathBuf::from(value), kind: BackgroundKind::Video, }), _ => Err(ParseError::NonBackgroundFile) } } } impl TryFrom for Background { type Error = ParseError; fn try_from(value: PathBuf) -> Result { let extension = value.extension().unwrap_or_default().to_str().unwrap_or_default(); match extension { "jpg" | "png" | "webp" => Ok(Self { path: value, kind: BackgroundKind::Image, }), "mp4" | "mkv" | "webm" => Ok(Self { path: value, kind: BackgroundKind::Video, }), _ => Err(ParseError::NonBackgroundFile) } } } #[derive(Debug)] pub enum ParseError { NonBackgroundFile, } impl Error for ParseError {} impl Display for ParseError { fn fmt( &self, f: &mut std::fmt::Formatter<'_>, ) -> std::fmt::Result { let message = match self { Self::NonBackgroundFile => "The file is not a recognized image or video type", }; write!(f, "Error: {message}") } } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum BackgroundKind { #[default] Image, Video, } impl From for BackgroundKind { fn from(value: String) -> Self { if value == "image" { BackgroundKind::Image } else { BackgroundKind::Video } } } #[derive(Clone, Debug, Default, PartialEq)] struct Slide { id: i32, database_id: i32, background: Background, text: String, font: String, font_size: i32, kind: ServiceItemKind, text_alignment: TextAlignment, service_item_id: i32, active: bool, selected: bool, video_loop: bool, video_start_time: f32, video_end_time: f32, obs_scene: ObsScene, } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] struct ObsScene; #[derive(Clone, Debug, Default, PartialEq)] struct SlideModel { slides: Vec, } impl From for Slide { fn from(_song: Song) -> Self { Self { kind: ServiceItemKind::Song, ..Default::default() } } } impl From