use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct Chapter {
    pub id: Uuid,
    pub manga_id: Uuid,
    pub number: i32,
    pub title: Option<String>,
    pub page_count: i32,
    pub created_at: DateTime<Utc>,
    /// Total bytes of this chapter's stored page images. `Some(0)` for an
    /// uncrawled chapter (no page rows). `None` when the size is unknown —
    /// at least one page predates the size backfill — so the frontend can
    /// show an em-dash instead of a misleading "0 B". `Some(n)` once every
    /// page in the chapter has a measured size.
    #[serde(default)]
    pub size_bytes: Option<i64>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct NewChapter {
    pub number: i32,
    pub title: Option<String>,
}
