use crate::services::types::ItemWithMeta;
use std::collections::HashMap;

pub fn extract_tags(items: &[ItemWithMeta]) -> Vec<String> {
    items
        .iter()
        .flat_map(|item| item.tags.iter())
        .map(|t| t.name.clone())
        .collect()
}

pub fn parse_comma_tags(s: &str) -> Vec<String> {
    s.split(',')
        .map(|t| t.trim().to_string())
        .filter(|t| !t.is_empty())
        .collect()
}

pub fn calc_byte_range(content_len: u64, offset: u64, length: Option<u64>) -> (u64, u64) {
    let start = std::cmp::min(offset, content_len);
    let end = match length {
        Some(len) if len > 0 => std::cmp::min(start + len, content_len),
        _ => content_len,
    };
    (start, end)
}
