use std::io::Result;

/// Creates a filter chain from a filter string specification.
///
/// # Arguments
///
/// * `filter_str` - The string describing the filter chain, such as "head_lines(10)|grep(pattern=error)"
///
/// # Returns
///
/// * `Result<Option<super::FilterChain>>` - A result containing:
///     * `Ok(Some(FilterChain))` if parsing succeeds
///     * `Ok(None)` if the filter string is empty
///     * `Err(io::Error)` if the string is invalid
pub fn create_filter_chain(filter_str: &str) -> Result<Option<super::FilterChain>> {
    super::parse_filter_string(filter_str).map(Some)
}

/// Parses a string into a number of type T.
///
/// # Arguments
///
/// * `s` - The string to parse into a number
///
/// # Returns
///
/// * `Result<T>` - A result containing:
///     * `Ok(T)` - The parsed number on success
///     * `Err(io::Error)` - If the string is not a valid number
pub fn parse_number<T: std::str::FromStr>(s: &str) -> Result<T> {
    s.parse::<T>()
        .map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "Invalid number"))
}
