//! Admin storage-usage stats. Pure data; assembled by
//! `crate::api::admin::storage` from `repo::storage_stats` aggregates
//! plus the storage backend's volume size.

use serde::Serialize;
use uuid::Uuid;

/// Storage usage of uploaded content (covers + chapter pages), for the
/// admin dashboard System tab. Sizes are bytes; the frontend formats
/// them with the binary (MiB/GiB) helper.
#[derive(Debug, Clone, Serialize)]
pub struct StorageStats {
    /// covers + chapter pages.
    pub total_bytes: i64,
    pub covers_bytes: i64,
    pub chapters_bytes: i64,
    /// Volume size of the storage root (`statvfs`). `None` when the
    /// backend has no local path (e.g. a future S3 backend).
    pub disk_total_bytes: Option<u64>,
    /// `total_bytes / disk_total_bytes`. `None` when the disk total is
    /// unknown — the frontend hides the ratio rather than fabricate one.
    pub ratio_of_disk: Option<f64>,
    /// Average image size across covers + chapter pages. `None` for an
    /// empty library (no division by zero).
    pub avg_image_bytes: Option<f64>,
    pub avg_cover_bytes: Option<f64>,
    pub avg_chapter_page_bytes: Option<f64>,
    /// Largest mangas by total stored bytes (cover + all chapter pages).
    /// Only fully-measured mangas are ranked.
    pub top_mangas: Vec<TopManga>,
    /// Largest chapters by total stored page bytes. Only fully-measured
    /// chapters are ranked.
    pub top_chapters: Vec<TopChapter>,
    /// Page rows still awaiting a size backfill. When > 0, every figure
    /// above is a partial (lower-bound) measurement and the leaderboards
    /// omit not-yet-measured content — the dashboard surfaces this so the
    /// numbers aren't read as complete.
    pub unmeasured_pages: i64,
    /// Cover blobs still awaiting a size backfill.
    pub unmeasured_covers: i64,
}

#[derive(Debug, Clone, Serialize)]
pub struct TopManga {
    pub id: Uuid,
    pub title: String,
    pub total_bytes: i64,
}

#[derive(Debug, Clone, Serialize)]
pub struct TopChapter {
    pub id: Uuid,
    pub manga_id: Uuid,
    pub number: i32,
    pub title: Option<String>,
    pub total_bytes: i64,
}
