use svgpack_parser::extract_title;

#[derive(Debug, Clone, Default)]
pub struct AnalysisReport {
    pub file_count: usize,
    pub total_bytes: usize,
    pub missing_titles: usize,
    pub has_raster_images: usize,
}

pub fn analyze(files: &[(String, String)]) -> AnalysisReport {
    let mut report = AnalysisReport::default();
    report.file_count = files.len();
    for (_, content) in files {
        report.total_bytes += content.len();
        if extract_title(content).is_none() {
            report.missing_titles += 1;
        }
        if content.contains("<image") && content.contains("data:image") {
            report.has_raster_images += 1;
        }
    }
    report
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn reports_missing_titles_and_raster_images() {
        let files = vec![
            (
                "a.svg".to_string(),
                "<svg><title>A</title></svg>".to_string(),
            ),
            (
                "b.svg".to_string(),
                "<svg><image href=\"data:image/png;base64,AAAA\"/></svg>".to_string(),
            ),
        ];
        let report = analyze(&files);
        assert_eq!(report.file_count, 2);
        assert_eq!(report.missing_titles, 1);
        assert_eq!(report.has_raster_images, 1);
    }
}
