use crate::utils::Chunk;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ChunkingConfig {
    pub chunk_size: usize,
}

/// Chunks data.
pub fn chunk_data(raw: &[u8], size: usize) -> Vec<Chunk> {
    raw.chunks(size)
        .map(|c| Chunk { data: c.to_vec() })
        .collect()
}

/// Simulates input.
pub fn simulate_input(size: usize) -> Vec<Chunk> {
    vec![Chunk {
        data: vec![0u8; size],
    }]
}

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

    /// Tests that chunk data splits input.
    #[test]
    fn chunk_data_splits_input() {
        let raw = b"abcdefgh";
        let chunks = chunk_data(raw, 3);
        assert_eq!(chunks.len(), 3);
        assert_eq!(chunks[0].data, b"abc");
        assert_eq!(chunks[1].data, b"def");
        assert_eq!(chunks[2].data, b"gh");
    }

    /// Tests that simulate input returns single zeroed chunk.
    #[test]
    fn simulate_input_returns_single_zeroed_chunk() {
        let chunks = simulate_input(5);
        assert_eq!(chunks.len(), 1);
        assert_eq!(chunks[0].data, vec![0u8; 5]);
    }

    #[test]
    fn chunking_config_copies_chunk_size() {
        let config = ChunkingConfig { chunk_size: 4 };
        assert_eq!(config.chunk_size, 4);
    }
}
