use anyhow::Result;
use clap::Args;
use systemprompt_database::DbPool;
use systemprompt_files::{FileService, FileStats};
use systemprompt_runtime::AppContext;
use super::types::{CategoryStat, FileCategoryStats, FileStatsOutput};
use crate::CliConfig;
use crate::shared::CommandResult;
#[derive(Debug, Clone, Copy, Args)]
pub struct StatsArgs;
pub async fn execute(
args: StatsArgs,
config: &CliConfig,
) -> Result<CommandResult<FileStatsOutput>> {
let ctx = AppContext::new().await?;
execute_with_pool(args, ctx.db_pool(), config).await
}
pub async fn execute_with_pool(
_args: StatsArgs,
pool: &DbPool,
_config: &CliConfig,
) -> Result<CommandResult<FileStatsOutput>> {
let service = FileService::new(pool)?;
let stats: FileStats = service.get_stats().await?;
let output = FileStatsOutput {
total_files: stats.total_files,
total_size_bytes: stats.total_size_bytes,
ai_images_count: stats.ai_images_count,
by_category: FileCategoryStats {
images: CategoryStat {
count: stats.image_count,
size_bytes: stats.image_size_bytes,
},
documents: CategoryStat {
count: stats.document_count,
size_bytes: stats.document_size_bytes,
},
audio: CategoryStat {
count: stats.audio_count,
size_bytes: stats.audio_size_bytes,
},
video: CategoryStat {
count: stats.video_count,
size_bytes: stats.video_size_bytes,
},
other: CategoryStat {
count: stats.other_count,
size_bytes: stats.other_size_bytes,
},
},
};
Ok(CommandResult::card(output).with_title("File Storage Statistics"))
}