use crate::{
    nest::NestValueType,
    transform::Transform,
};

/// # Generic parameters
///
/// - `T`: The source value type
/// - `V`: The resulting type used in the nest (must implement [`NestValueType`])
pub trait BuildNestValue<T, V>: Transform
where
    V: NestValueType
{
    fn build_nest_value(&self, source: &T, options: &Self::Options) -> V;
}

/// Auto-implement for option -> option
impl<I, O, T> BuildNestValue<Option<I>, Option<O>> for T where
    O: NestValueType,
    T: Transform,
    Self: BuildNestValue<I, O>,
{
    fn build_nest_value(&self, source: &Option<I>, options: &Self::Options) -> Option<O> {
        source.as_ref().map(|s| {
            self.build_nest_value(s, options)
        })
    }
}
