#![allow(unused)] use serde::Serialize; use crate::types::{ Chapter, ContentRating, Manga, PublicationDemographic, State, Status, Titles, }; use crate::language::Language; use chrono::{DateTime, FixedOffset}; #[derive(Serialize)] pub struct Metadata { title: String, original_language: Language, last_volume: f32, last_chapter: f32, publication_demographic: Option, status: Status, year: Option, content_rating: ContentRating, state: State, created_at: String, updated_at: String, chapters: Vec, } #[derive(Clone, Serialize)] struct ChapterMetadata { chapter: f32, volume: f32, title: Option, pages: u32, } impl Metadata { pub fn new(manga: Manga, chapters: Vec) -> Self { let attributes = manga.attributes; Self { title: attributes.title.en, original_language: attributes.original_language, last_volume: attributes.last_volume.unwrap(), last_chapter: attributes.last_chapter.unwrap(), publication_demographic: attributes.publication_demographic, status: attributes.status, year: attributes.year, content_rating: attributes.content_rating, state: attributes.state, created_at: attributes.created_at.to_string(), updated_at: attributes.updated_at.to_string(), chapters: chapters .iter() .map(|m| ChapterMetadata { chapter: m.attributes.chapter.unwrap(), volume: m.attributes.volume.unwrap(), title: m.attributes.title.clone(), pages: m.attributes.pages, }) .collect(), } } }